【发布时间】:2021-01-22 18:44:41
【问题描述】:
用例:
我有一个自定义钩子useFoo,它需要根据存储中的bar 属性返回值,但打字稿会抛出错误。
代码:
export const useFoo = observer(() => {
// typescript throws error --^^^^^^^--
const { bar } = store;
return bar ? 'x' : 'y';
});
打字稿错误:
Argument of type '() => "x" | "y"' is not assignable to parameter of type 'IReactComponent<any>'.
Type '() => "x" | "y"' is not assignable to type 'FunctionComponent<any>'.
Type '"x" | "y"' is not assignable to type 'ReactElement<any, any> | null'.
Type '"x"' is not assignable to type 'ReactElement<any, any> | null'.ts(2345)
【问题讨论】:
标签: reactjs typescript redux react-hooks mobx