react-beautiful-dnd icon indicating copy to clipboard operation
react-beautiful-dnd copied to clipboard

Builtin package @types/react is not works

Open yzw7489757 opened this issue 2 years ago • 2 comments

'DragDropContext' cannot be used as a JSX component

TS2786: 'DragDropContext' cannot be used as a JSX component.
  Its instance type 'DragDropContext' is not a valid JSX element.
    The types returned by 'render()' are incompatible between these types.
      Type 'React.ReactNode' is not assignable to type 'import("path/node_modules/@types/hoist-non-react-statics/node_modules/@types/react/index").ReactNode'.
    72 |   }
    73 |
  > 74 |   return <DragDropContext onDragEnd={onDragEnd} >
       |                  ^^^^^^^^^^^^^^^
    75 |     <Droppable
    76 |       droppableId={dropIdWithPrefix.current}
    77 |       direction={direction}
{
    "devDependencies": {
        "@types/react": "17.0.30",
        "@types/react-beautiful-dnd": "^13.1.2",
        "@types/react-dom": "^17.0.14",
        "typescript": "^4.6.2"
    },
    "dependencies": {
        "react": "^17.0.2",
        "react-beautiful-dnd": "^13.1.0",
        "react-dom": "^17.0.2"
    },
    "resolutions": {
        "@types/react": "17.0.30"
    }
}

It will install @types/react, so use the "resolutions" constraint version, but it is still invalid。

image
npm i 

yzw7489757 avatar Apr 12 '22 02:04 yzw7489757

Got the same problem on existing project. Tried to delete node_modules and reinstall. Nothing helped. Then created a project from scratch with npx create-react-app proj --template typescript - and it worked with same set of deps.

hexwit avatar Jul 08 '22 15:07 hexwit

Got the same problem upgrading @types/react from 17 to 18. Solved by deleting my node modules directory and lockfile and reinstalling.

rm -rf node_modules
rm yarn.lock
yarn install

aarsilv avatar Oct 19 '23 19:10 aarsilv