我有以下旧代码(有效)
const wrapper: <T>(props: IOwnProps<T>) => ReactElement<IOwnProps<T>> = props => {
const C: any = withStyles(styles)(Select);
return React.createElement(C, props);
};
如果我尝试删除any
,则会出现此错误:
Error:(195, 33) TS2345: Argument of type 'IOwnProps<T>' is not assignable to parameter of type 'Attributes & Pick<PropsWithStyles<{}>, "label" | "itemToString" | "itemIdentifier" | "options" | "selected" | "load" | "onChange"> & StyledComponentProps<"root" | "label" | "paper">'.
Type 'IOwnProps<T>' is not assignable to type 'Pick<PropsWithStyles<{}>, "label" | "itemToString" | "itemIdentifier" | "options" | "selected" | "load" | "onChange">'.
Types of property 'itemToString' are incompatible.
Type '(item: T) => string' is not assignable to type '(item: {}) => string'.
Types of parameters 'item' and 'item' are incompatible.
Type '{}' is not assignable to type 'T'.
我应该怎么做才能使其编译?