I cannot get React.createElement to compile in TypeScript.
interface IColorPickerProps {
}
interface IColorPickerState {
}
class ColorPicker extends React.Component<IColorPickerProps, IColorPickerState> {
constructor(props: IColorPickerProps) {
super(props);
}
}
Component creation:
let props: any = {}
React.createElement(ColorPicker, props)
I get this compile error:
Argument of type 'typeof ColorPicker' is not assignable to parameter of type 'string | ComponentClass<IColorPickerProps> | StatelessComponent<IColorPickerProps>'.
Type 'typeof ColorPicker' is not assignable to type 'StatelessComponent<IColorPickerProps>'.
Type 'typeof ColorPicker' provides no match for the signature '(props: IColorPickerProps & { children?: ReactNode; }, context?: any): ReactElement<any> | null'.
If I remove the constructor, the error goes away. I cannot use the syntax as props needs to be passed dynamically. Any ideas?
React.createElement(ColorPicker, props)while you can just<ColorPicker/>?<ColorPicker myProp={props["name"]}/>would lose compile time checking, whileReact.createElement(ColorPicker, props)does not.