Definitelytyped: [@types/react] Argument of type 'Element' is not assignable to parameter of type 'ReactElement<any>'.

Created on 28 Dec 2018  路  6Comments  路  Source: DefinitelyTyped/DefinitelyTyped

"@types/react": "16.7.13" works.
"@types/react": "16.7.14" and "@types/react": "16.7.18" (latest) throws this error.

Using "typescript": "3.2.2".

Most helpful comment

Adding the following to my package.json resolved the issue.

"resolutions": {
  "@types/react": "16.7.18"
}

Seems pretty silly that we need an override just to upgrade a type definition. Shouldn't this be a breaking change?

All 6 comments

Downgraded to "@types/react": "16.7.13"

https://github.com/DefinitelyTyped/DefinitelyTyped/commit/c2367fab52cf48fafa9daa915f0714a81d3c122f#diff-96b72df8b13a8a590e4f160cbc51f40c this commit replaced ValidationMap to WeakValidationMap on propTypes? in the following interfaces

RefForwardingComponent
ComponentClass

Only replacing in RefForwardingComponent did not create any errors.
The error created is the following:

      TS2345: Argument of type 'Element' is not assignable to parameter of type 'ReactElement<any>[]'.
  Type 'Element' is missing the following properties from type 'ReactElement<any>[]': length, pop, push, concat, and 26 more.

===================

I dug a deeper, downloaded "@types/react": "16.7.18"
Replaced WeakValidationMap with ValidationMap in ComponentClass and FunctionComponent and the error went away

Please check to see if you have duplicate React types installed in your node_modules first:
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/17161#issuecomment-446933731

Adding the following to my package.json resolved the issue.

"resolutions": {
  "@types/react": "16.7.18"
}

Seems pretty silly that we need an override just to upgrade a type definition. Shouldn't this be a breaking change?

The DT repository does not follow semver, so all changes are potentially breaking changes. That said the react types gets affected by duplicated versions more often because it's a fairly central dependency to most component libraries.

Okay. Good to know. Thanks for the help!

Adding the resolutions did solve my issue.
But somehow yarn remove @types/react + yarn add @types/react did. It definitely looks like multiple-react-types issue.

Was this page helpful?
0 / 5 - 0 ratings