Skip to content

@tanstack/react-form: declare @types/react as an optional peer dependency #2472

Open

Description

@patricklafrance

Summary

@tanstack/react-form ships type declarations that import from react but doesn'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: @tanstack/react-form@1.33.5

Reproduction

pnpm 12.18.0:

mkdir repro && cd repro
echo '{ "name": "repro", "private": true }' > package.json
echo 'virtualStoreType: global' > pnpm-workspace.yaml
pnpm add @tanstack/react-form react react-dom @types/react typescript
echo 'import "@tanstack/react-form";' > 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions