打字稿回调函数返回函数

时间:2020-02-08 22:44:26

标签: typescript

我有以函数为参数并返回新函数的函数。返回的函数用gem rails参数调用,然后调用options函数。 我不知道如何将styleCallback类型传递给options

styleCallback

我尝试使用泛型,但是没有用

const makeStyle = (styleCallback) => {
    return (options) =>{
        theme = getTheme();
        return styleCallback(theme, options)
    }
}

1 个答案:

答案 0 :(得分:1)

将type变量放在主函数中应该可以解决您的问题。

const makeStyle = <T>(styleCallback: (theme: Theme, props: T) => any) => {
    return (options: T) => {
        let theme = getTheme();
        return styleCallback(theme, options);
    }
}