SolvedDefinitelyTyped Subsequent property declarations must have the same type...
✔️Accepted Answer
@allada I was able to reproduce with your pinned versions using yarn (are you using yarn?) - here's what's going on.
This is the package.json
:
{
"dependencies": {
"@types/react": "16.3.9",
"@types/react-dom": "16.0.5",
"react": "16.3.1",
"react-dom": "16.3.1",
"typescript": "^2.8.3"
}
}
So you'll get @types/react
at version 16.3.9 and @types/react-dom
at version 16.0.5, because you explicitly asked for those. However, @types/react-dom
lists a dependency on @types/react
as the following:
"@types/react": "*"
Yarn interprets this as "the latest version of @types/react
", so it installs an additional version of the package. You can see this in the resulting yarn.lock
:
"@types/react-dom@16.0.5":
version "16.0.5"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.0.5.tgz#a757457662e3819409229e8f86795ff37b371f96"
dependencies:
"@types/node" "*"
"@types/react" "*"
"@types/react@*":
version "16.3.12"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.3.12.tgz#68d9146f3e9797e38ffbf22f7ed1dde91a2cfd2e"
dependencies:
csstype "^2.2.0"
"@types/react@16.3.9":
version "16.3.9"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.3.9.tgz#15be16b53c89aac558cf6445774502b2792555ff"
dependencies:
csstype "^2.2.0"
So you will have versions v16.3.9 and v16.3.12 of the types package simultaneously being used, which causes the error.
There's two ways I know of to fix this:
-
Update to the latest version of the
@types/react
package in yourpackage.json
-
Add a resolutions section to your
package.json
to tell Yarn to resolve the dependency differently:{ "resolutions": { "@types/react": "16.3.9" }, "dependencies": { "@types/react": "16.3.9", "@types/react-dom": "16.0.5", "react": "16.3.1", "react-dom": "16.3.1", "typescript": "^2.8.3" } }
I tried npm v5.6.0 and it does not seem to have the same problem as it interprets a dependency on *
as "any".
This is being tracked as an issue with Yarn at yarnpkg/yarn#4489.
Other Answers:
as suggested by @jacobwgillespie
Note that most of the time, what's going on is you have a particular dependency like @types/react
duplicated in your yarn.lock
. For instance if you have a version of the package that is depended on by two other packages, then you upgrade one of those packages, Yarn will oftentimes add a second entry for the shared dep.
The fix for me is usually manually removing the resolutions for @types/react
from the yarn.lock
file, then re-running yarn
so that it's re-locked as a single dependency.
Also as a side note, you may want to check that you don't have multiple versions of
@types/react
inside youryarn.lock
. Yarn can incorrectly resolve the package when upgrading: #24711.There are some fixes mentioned there in that thread, or you can manually edit your
yarn.lock
, remove all the instances of@types/react
and then re-runyarn install
to make it re-resolve.
I deleted yarn.lock
, reinstalled the modules and everything working for me now, thanks!
Fixed by adding resolutions to package.json
as suggested by @jacobwgillespie
"resolutions": {
"@types/react": "16.3.18"
},
Latest changes by @jacobwgillespie @RyanCavanaugh may have caused this issue. "@ types/react": "^16.3.11" causes this error because it loads 16.3.12 which breaks. Removing ^ from the version like "16.3.11" fixes the problem.
The TS starter kit of Microsoft fails too. https://github.com/Microsoft/TypeScript-React-Starter