【发布时间】:2019-05-12 07:29:34
【问题描述】:
我正在使用 React on Rails |打包机 |打字稿:“^2.8.1”。
我有一个高阶组件,它接受一个组件并在其中注入一些道具,然后返回它:
export type HCProps = {
isValid: boolean,
};
然后我有一个组件,它从高阶组件中获取注入的道具:
import injector, { HCProps } from './HCComponent';
type Props = {};
const LocalComponent: React.SFC<Props & HCProps> = ({ isValid }) => (
);
export default injector(LocalComponent);
这里的LocalComponent在渲染为组件时没有像DOM属性那样接受任何props,但是props是由HCComponent注入的:
<LocalComponent />
这给了我错误:
Type '{}' is not assignable to type 'IntrinsicAttributes & HCProps & Props & { children?: ReactNode; }'.
Type '{}' is not assignable to type 'HCProps'.
Property 'isValid' is missing in type '{}'.
知道为什么会这样吗?我是打字稿的新手。
【问题讨论】:
标签: javascript reactjs typescript react-props