SolvedDefinitelyTyped react is at 16.3.1 and react-dom at 16.0.4

This is creating a typescript compile error due to incompatibility between react and react-dom d.ts versions.

Subsequent property declarations must have the same type. Property 'a' must be of type 'DetailedHTMLProps<AnchorHTMLAttributes, HTMLAnchorElement>', but here has type 'DetailedHTMLProps<AnchorHTMLAttributes, HTMLAnchorElement>

I've overcome the issue for now by placing this in my package.json

    "@types/react": "^16.0.40",
    "@types/react-dom": "^16.0.4",
12 Answers

✔️Accepted Answer

Alright, here's a way to fix this pretty nicely for now.

In your package.json add:

  "resolutions": {
    "@types/react": "16.3.11"

As documented by Yarn here this will override sub-dependency versions to resolve to your targeted version. You can use a glob pattern too.

For me, I did this, then updated to the latest @types/react-router-dom and it used the new @types/react version 👍 If you're on latest, Yarn might want you to re-install the same package so it resolves via the new resolution.

Other Answers:

Ok, I found out it was a yarn problem.
Somehow it does not correctly dedupe the dependencies.
Try deleting your yarn.lock and let it create a fresh one, then it worked for me with the most recent @types/react version.

Deleting yarn.lock (and even the whole node_modules folder) did not remove the errors for me.


    "react": "^16.3.1",
    "react-dom": "^16.3.1",
    "react-router-dom": "^4.2.2",
    "@types/react": "^16.3.5",
    "@types/react-dom": "^16.0.4",
    "@types/react-router": "^4.0.23",
    "@types/react-router-dom": "^4.2.6"

@types/react-dom also exports react types, but has not been updated to correspond with @types/react 16.3. So you get a conflict between the types exported from the two modules.

Workaround: You can use react 16.3 now by temporarily removing @types/react and including only @types/react-dom. The downside is that if you want to use new features in 16.3 -- like createRef() and context apis, you need to sprinkle as any on them, because the type definitions in @types/react-dom 16.0 don't have those apis yet.

Of course, the real solution is for @types/react-dom to be updated to match @types/react 16.3.

More Issues: