react: change default type value of snapshot to any#24987
Merged
RyanCavanaugh merged 4 commits intoDefinitelyTyped:masterfrom Apr 19, 2018
jacobwgillespie:react-snapshot-default
Merged
react: change default type value of snapshot to any#24987RyanCavanaugh merged 4 commits intoDefinitelyTyped:masterfrom jacobwgillespie:react-snapshot-default
RyanCavanaugh merged 4 commits intoDefinitelyTyped:masterfrom
jacobwgillespie:react-snapshot-default
Conversation
This was referenced Apr 14, 2018
Contributor
|
@jacobwgillespie Thank you for submitting this PR! 🔔 @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @morcerf @tkrotoff @DovydasNavickas @onigoetz @theruther4d @guilhermehubner @JoshuaKGoldberg @jrakotoharisoa - 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. |
Contributor
|
After 5 days, no one has reviewed the PR 😞. A maintainer will be reviewing the PR in the next few days and will either merge it or request revisions. Thank you for your patience! |
Member
|
🌟 🎈 🎉 🏆 🎂 ✨ ⭐️ Congratulations on your first DefinitelyTyped contribution! 🌟 🎈 🎉 🏆 🎂 ✨ ⭐️ |
cmaddalozzo
pushed a commit
to cmaddalozzo/DefinitelyTyped
that referenced
this pull request
Apr 20, 2018
* 'master' of github.com:DefinitelyTyped/DefinitelyTyped: (181 commits) [Joi] - add schema option to .when (DefinitelyTyped#25136) @types/mapbox-gl maxDuration property in FlyToOptions (DefinitelyTyped#25088) Glue - Fix to plugins (DefinitelyTyped#25141) add addEventListener to eventsource (DefinitelyTyped#25125) Adding more siblings to Red interface in node-red (DefinitelyTyped#25013) [knex] Add QueryBuilder to knex.raw bindings (DefinitelyTyped#25100) react: change default type value of snapshot to any (DefinitelyTyped#24987) added typings for mapbox-gl-leaflet (DefinitelyTyped#25120) React animate on scroll (DefinitelyTyped#25131) Fixed AccountResponse's signers' object (DefinitelyTyped#25095) React-navigation onTransition event pass props (DefinitelyTyped#25121) dotenv-safe 5.0 (DefinitelyTyped#25124) change member types from variable to method (DefinitelyTyped#25097) Updating react-native-drawer definitions from 2.3 to 2.5 (DefinitelyTyped#25118) Added the statement of ActiveSelection (DefinitelyTyped#25084) [THREE] add Curve.arcLengthDivisions (DefinitelyTyped#25116) [atom] Support version v1.26. (DefinitelyTyped#25111) [adone] refactoring, additions (DefinitelyTyped#25114) (react-native-modalbox) Remove ViewProperties from main props (DefinitelyTyped#25128) added typings for npm package ng-tags-input (DefinitelyTyped#24946) ...
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the
reacttypes, the definition ofReact.ComponentisReact.Component<P = {}, S = {}, SS = never>, meaning that type-wise, props defaults to{}, state defaults to{}, and snapshot defaults tonever. Snapshot is used as the return value of the new ReactgetSnapshotBeforeUpdatelifecycle method, whose return type isSS | null.What that means, however, is that unless the third generic type parameter is overridden, the return value of
getSnapshotBeforeUpdateis resolved tonever | null, which is resolved tonull. This causes an issue where any components that do definegetSnapshotBeforeUpdateare unable to be used by something expecting aReact.Component, becausegetSnapshotBeforeUpdatereturns something other than null.This PR changes the default to be
SS = any, which allows other libraries to do things like the following:There are many third-party libraries that do something similar, which I believe necessitates this change. Additionally, at the moment it is not possible to even use a component that uses the new lifecycle method as it is not considered to be a valid JSX component type (for the same reason, see #24820).
I have added several test cases to catch actually using components that contain
getSnapshotBeforeUpdate, using them withReact.createElement, and using the new lifecycle method onPureComponent, which previously did not accept theSStype param.Fixes #24820. See #24820 for more context. Replaces #24985.
npm test.)npm run lint package-name(ortscif notslint.jsonis present).If changing an existing definition:
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }.