SolvedDefinitelyTyped Aphrodite: incompatible with @types/react 15.6.0?

@types/aphrodite 0.5.6 appears to be incompatible with @types/react 15.6.0 and a few versions before that. For all HTML element types, I see a message of the form:

Error:(2989, 13) TS2403:Subsequent variable declarations must have the same type. Variable 'a' must be of type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>', but here has type 'HTMLProps<HTMLAnchorElement>'.

complaining about <my project>/node_modules/@types/aphrodite/node_modules/@types/react/index.d.ts

The element definitions have changed, e.g.

Aphrodite's embedded react/index.d.ts:
a: React.HTMLProps<HTMLAnchorElement>;
15.6.0
a: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;

When fixing this, consider changing the @types/aphrodite/package.json dependency:

"dependencies": {
        "@types/react": "*"
    },

to require 15.6 or better.

@types/aphrodite 0.5.6 is compatible with @types/react 15.0.35, which I've fallen back to.

I'm a noob at dealing with these kinds of version-dependency issues on libs, especially on @types. Otherwise, I'd PR it. I have no idea how the @types/aphrodite/package.json is generated, or how @types/aphrodite/node_modules is filled, or where the @types/react version '15.0.83' is specified.

@tkrotoff fyi

26 Answers

✔️Accepted Answer

Adding React to the paths object in my tsconfig.json file solved the issue for me for now:

{
    "compilerOptions": {
        "typeRoots": [
            "node_modules/@types"
        ],
        "paths": {
            "react": ["node_modules/@types/react"] <---Here
        }
}

Other Answers:

Not sure what's going on, but I'm getting similar issues with @types/react-redux and @types/react-dom. Bizarrely, npm install produces a working node_modules but yarn results in a node_modules that's broken:
https://gist.github.com/ajaska/e3ae7420946ece1e91e73cf614f6d2a3

I took a look at this; yarn creates those sub-node_modules directories (so getting different versions? unsure) but npm install doesn't?

  "dependencies": {
    "@types/react": "^15.0.38",
    "@types/react-dom": "^15.5.1",
    "@types/react-redux": "^4.4.46",
    "react": "^0.14.9",
    "react-dom": "^0.14.9",
    "react-redux": "^5.0.5",
}

I removed the package.json entry of @types/react-dom and re install using yarn add @types/react-dom and it seems to be ok now for me

And again, yarn will produce a broken node_modules whereas npm install will produce one that functions just fine.

Add

"resolutions": {
   "@types/react": "^16.0.40"
 }

to package.json

Reinstall node_modules with yarn install

Note it's a bit hacky to force package version for every package in node_modules, but in case of @types it's rather safe.

More Issues: