react-router icon indicating copy to clipboard operation
react-router copied to clipboard

[Bug]: react-rotuer-dom 6.2.1 (and 6.3.0) depend on react 18 types causing issue with react 17

Open lucas-paulger-sonarsource opened this issue 4 years ago • 4 comments

What version of React Router are you using?

react-router-dom 6.2.1

Steps to Reproduce

install these versions

  "react": "17.0.2",
  "react-dom": "17.0.2",
  "react-router-dom": "6.2.1",
  "@types/react": "17.0.2",
  "@types/react-dom": "17.0.2",

and then run a type check tsc --noEmit

Expected Behavior

no typing errors

Actual Behavior

$ tsc --noEmit
node_modules/react-router-dom/index.d.ts:77:20 - error TS2694: Namespace 'React' has no exported member 'HTMLAttributeAnchorTarget'.

77     target?: React.HTMLAttributeAnchorTarget;
                      ~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error.

Reviewing the types of react 17.0.2 and react 18.0.0, I see that HTMLAttributeAnchorTarget only exists in react 18

https://www.jsdocs.io/package/@types/react/v/17.0.2 https://www.jsdocs.io/package/@types/react/v/18.0.0

Is there a way to workaround this? Encountering the issue via Storybook

Related: https://github.com/storybookjs/storybook/issues/16925

simonsmith avatar Apr 25 '22 16:04 simonsmith

The bug is actually in v17.0.2 of @types/react where this type is missing, while it's present in v16, v18, or the more recent typing version for React 17: v17.0.44 If you make sure to use "@types/react": "17.0.44" it should work fine.

gregaubert avatar Apr 27 '22 15:04 gregaubert

@gregaubert Yep, that worked for me also. Thanks 👍🏻

simonsmith avatar May 03 '22 14:05 simonsmith

Looks like this is fixed upstream.

timdorr avatar May 04 '22 16:05 timdorr