Typescript support
See original GitHub issueI’ve been looking into adding Typescript support to this library. Here are the issues I encountered.
-
JSX factory invocations (eg:
<Foo />
) returnReactElement<any>
(but a fix is on the way), which means we can’t infer the prop types of any returned elements -
This is only true if you explicitly type your stateless component using@types/react
does not allow thechildren
prop to be a function (at least with “stateless components”)React.SFC
-
Typescript cannot infer what
yield
returns, which means render props are untyped by default https://github.com/Microsoft/TypeScript/issues/26959
Now I’m wondering if “yield
to wrap the next yield
or return
” is worth the lack of type safety, or if I should bite the bullet on using render props without this library. 😞
If generators were always immutable in Javascript, this would be a lot easier.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top GitHub Comments
The best workaround is something like:
And then:
Example: https://codesandbox.io/s/qqonn05154?view=editor (note: CodeSandbox is using TS 2.7 so not exactly a working example right now)
Just to share my config which works so-and-so (having typing issues with yielded elements not having an explicit children prop)