-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Description
- I tried using the
@types/reactpackage and had problems. - I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
- I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
- Mention the authors (see
Definitions by:inindex.d.ts) so they can respond.- Authors: @johnnyreilly, @bbenezech, ...
With current typings it is not possible to create a stateless component which returns a string, number, boolean... (new in React 16)
import React from 'react'
const TestString = () => {
return 'Test String Component'
}
const Component = () => (
<div>
<TestString/>
</div>
)Error I get:
JSX element type 'string' is not a constructor function for JSX elements.
The first problem is that currently in the typings a stateless component cannot return anything else besides an instance of a React.Element. This should be changed to (I think, I've based it upon the changes on the rendermethod, see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L422)
interface StatelessComponent<P = {}> {
(props: P & { children?: ReactNode }, context?: any): ReactElement<any> | Array<ReactElement<any>> | string | number | null;
propTypes?: ValidationMap<P>;
contextTypes?: ValidationMap<any>;
defaultProps?: Partial<P>;
displayName?: string;
}
Second problem is that behind the scenes the compiler will convert the jsx to `React.createElement('Test String Component', null)``
I get a compiler error that is saying that this is not a valid value. Seems that it has to be one of the values specified in following list: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L3465.
Any thoughts on how this can be fixed?