Skip to content

Conversation

@ferdaber
Copy link
Contributor

@ferdaber ferdaber commented Dec 11, 2018

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: @types/react 16.4.8 breaks prop-types #28015 (comment)
  • Increase the version number in the header if appropriate.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }.

cc @andrewbranch


export interface ReactElementLike {
type: string | ((...args: any[]) => ReactElementLike);
type: ReactComponentLike;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed a longstanding issue with these DTSLint assertions


type ValidationMap<T> = PropTypes.ValidationMap<T>;

type WeakValidationMap<T> = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the problem was a different issue (cc @cuyl) - I've written the fix here:

#17161 (comment)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Awaiting reviewer feedback Author is Owner The author of this PR is a listed owner of the package. labels Dec 11, 2018
@typescript-bot
Copy link
Contributor

typescript-bot commented Dec 11, 2018

@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 Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@typescript-bot
Copy link
Contributor

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!

@johnnyreilly johnnyreilly merged commit c2367fa into DefinitelyTyped:master Dec 12, 2018
@johnnyreilly
Copy link
Member

Thanks!

@milesj
Copy link
Contributor

milesj commented Dec 12, 2018

@Jessidhia
Copy link
Member

Unfortunately no, it requires bumping @types/react to TS 3.0.

@ferdaber
Copy link
Contributor Author

@milesj if you were asking if those tests passed, I did test them out and they did not error for TS 3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author is Owner The author of this PR is a listed owner of the package. Popular package This PR affects a popular package (as counted by NPM download counts).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants