react: allow the use of getSnapshotBeforeUpdate#24985
react: allow the use of getSnapshotBeforeUpdate#24985jacobwgillespie wants to merge 3 commits intoDefinitelyTyped:masterfrom jacobwgillespie:fix-react-getsnapshotbeforeupdate
Conversation
|
Well, I'm not sure why the initial test commit isn't failing on Travis CI - locally if I run |
| return this.state.bar; | ||
| } | ||
| } | ||
| <ComponentWithNewLifecycles foo="bar" />; |
There was a problem hiding this comment.
Does it also work with React.createElement?
|
@jacobwgillespie Thank you for submitting this PR! 🔔 @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @morcerf @tkrotoff @DovydasNavickas @onigoetz @theruther4d @guilhermehubner @JoshuaKGoldberg @jrakotoharisoa @MartynasZilinskas - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
|
@Kovensky, so while fixing the examples for I think it might not be possible to have The only thing I know of would be to change interface Component<P = {}, S = {}, SS = any> extends ComponentLifecycle<P, S, SS> { }Is that best? I know TypeScript 2.8 has the ability to infer the return type of a function, is there some way to use that here so that the type doesn't have to be specified on the |
|
Yeah, the tests failed here as |
|
@jacobwgillespie The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
I have opened #24987 to replace this PR - closing. |
In the
reacttypes, the definition ofJSX.ElementClassisextends React.Component<any>. This means that it overrides the default generic for propsPto beany, but it accepts the default values for the other two generics, stateSand the new snapshotSS. This means that it assumes all ElementClass instances are:P:anyS:{}SS:neverThis causes an issue that prevents using any components that use the new
getSnapshotBeforeUpdatelifecycle method, because this forces it to only accept the value ofnever | nullas the snapshot type.This PR updates the definition of
JSX.ElementClassto beextends React.Component<any, {}, any>, which will then accept the following types:P:anyS:{}SS:anyThis makes it possible to use
getSnapshotBeforeUpdate.The first commit in this PR adds a failing test. The second commit makes the definition change.
Fixes #24820. See #24820 for more context.
npm test.)npm run lint package-name(ortscif notslint.jsonis present).If changing an existing definition:
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }.