[react] allow weaker prop declarations for nullish properties#31280
Conversation
|
|
||
| export interface ReactElementLike { | ||
| type: string | ((...args: any[]) => ReactElementLike); | ||
| type: ReactComponentLike; |
There was a problem hiding this comment.
The original type property for this was not exactly the same as the one in the React type definitions, causing issues with the PropTypes.element validator, which this fixes.
| type ExtractedPropsFromOuterPropsWithoutAnnotation = PropTypes.InferProps<typeof outerPropTypesWithoutAnnotation>['props']; | ||
|
|
||
| // $ExpectType: true | ||
| // $ExpectType true |
There was a problem hiding this comment.
Fixed a longstanding issue with these DTSLint assertions
|
|
||
| type ValidationMap<T> = PropTypes.ValidationMap<T>; | ||
|
|
||
| type WeakValidationMap<T> = { |
There was a problem hiding this comment.
The weak validation map will transform any prop declaration that can be null or undefined and widen it to be both: null | undefined. This allows props authors to declare something like this:
type Props = { foo?: string }and have it pass checks for HOCs that require it to be:
type Props = { foo?: string | null }Most developers do not realize that propTypes allows for both so this should meet a compromise of DX and runtime accuracy.
There was a problem hiding this comment.
Hi @ferdaber, after upgrading @types/react to 16.7.14 from 16.7.13, my project is getting
TS2605: JSX element type 'ReactElement<any> | null' is not a constructor function for JSX elements.
Type 'ReactElement<any>' is not assignable to type 'Element'.
for almost every component. I've tracked down this bug into these changes. I'm wondering if anyone else is getting this error...I'll try to create a reproducible repo soon.
There was a problem hiding this comment.
Actually, the problem was a different issue (cc @cuyl) - I've written the fix here:
|
@ferdaber Thank you for submitting this PR! 🔔 @DovydasNavickas @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @tkrotoff @onigoetz @theruther4d @guilhermehubner @jrakotoharisoa @pascaloliv @Hotell @franklixuefei @Kovensky - 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. |
|
Since you're a listed owner and the build passed, this PR is fast-tracked. A maintainer will merge shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
|
Thanks! |
|
Would this satisfy the commented out tests here? https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/test/managedAttributes.tsx |
|
Unfortunately no, it requires bumping |
|
@milesj if you were asking if those tests passed, I did test them out and they did not error for TS 3.0. |
Please fill in this template.
npm test.)npm run lint package-name(ortscif notslint.jsonis present).If changing an existing definition:
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }.cc @andrewbranch