Declare @types/react as an optional peer dependency

Open Beginner friendly
#2,181 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@abd1rahmane is already working on this.

Since Nov 14, 2026.

  • #2189 by @abd1rahmane — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
react, typescript
Domain
build-system

Research direction

Start by checking the package manifests for @dnd-kit/core, @dnd-kit/sortable, and @dnd-kit/utilities, then compare their React peer dependency ranges and peer dependency metadata. Reproduce the resolution issue with the pnpm commands in the issue and inspect the TypeScript trace. Done when each affected package declares optional @types/react and the reproduction resolves React types correctly.

Written by the indexing model from the issue text.

Description

Summary

@dnd-kit/core, @dnd-kit/sortable, @dnd-kit/utilities ship type declarations that import from react but don't declare @types/react.

With an install layout where packages live outside the project, such as pnpm's global virtual store (virtualStoreType: global), TypeScript resolves react from the package's real path. The react peer is linked next to the package, @types/react is not, so TypeScript picks the untyped react/index.js and every React type in these declarations silently becomes any.

Consumers see it as errors in their own code, for example TS7006: Parameter 'x' implicitly has an 'any' type on callback parameters, or component props that lose children and className. Under pnpm's default layout it only works through pnpm's hidden hoisting fallback (node_modules/.pnpm/node_modules).

Affected versions: @dnd-kit/[email protected], @dnd-kit/[email protected], @dnd-kit/[email protected]

Reproduction

pnpm 12.18.0:

mkdir repro && cd repro
echo '{ "name": "repro", "private": true }' > package.json
echo 'virtualStoreType: global' > pnpm-workspace.yaml
pnpm add @dnd-kit/core react react-dom @types/react typescript
echo 'import "@dnd-kit/core";' > index.ts
pnpm exec tsc --noEmit --traceResolution --module esnext --moduleResolution bundler --jsx react-jsx index.ts | grep "Module name 'react' was"

Expected: react resolves to @types/react/index.d.ts.

Actual: .../pnpm/store/v11/links/@/react/<version>/<hash>/node_modules/react/index.js

Suggested fix

"peerDependencies": {
    "@types/react": "*"
},
"peerDependenciesMeta": {
    "@types/react": { "optional": true }
}

Optional, so JavaScript consumers are unaffected. The range can mirror the existing react peer range. react-router, @tanstack/react-query and recharts (recharts#7710) do the same.

Consumer-side workarounds until then: pnpm's addMissingPeerTypes (pnpm 12.12+) or packageExtensions. Related: pnpm/pnpm#9739.

Dominant language
TypeScript
Stars
17.8k
Forks
934
Avg merge
1d 4h
Merged PRs (30d)
7

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from clauderic/dnd-kit

All issues in clauderic/dnd-kit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.