feat: add optional @types/react peer dependency - #2722
Open
unrevised6419 wants to merge 1 commit into
Open
unrevised6419 wants to merge 1 commit into
unrevised6419 wants to merge 1 commit into
Conversation
The shipped .d.ts files import from 'react', but only the react runtime peer is declared. Under package layouts where react-use is installed outside the consumer's tree (pnpm virtualStoreType: global), TypeScript resolves that import from where react-use physically sits and lands on react/index.js instead of a declaration file, silently degrading every type fed by those declarations to any. Declaring @types/react as an optional peer at "*" makes the types resolvable without introducing a version claim or affecting non-TypeScript consumers.
unrevised6419
force-pushed
the
pr/optional-types-react-peer
branch
from
September 24, 2026 03:08
118fc0a to
8f2333d
Compare
unrevised6419
marked this pull request as ready for review
September 24, 2026 03:26
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
react-useshipslib/index.d.ts/esm/index.d.tswhose declarations import fromreact, butpackage.jsondeclares only thereactruntime peer. That is fine when the package is installed inside the consumer'snode_modules, and broken when it is not.Under pnpm's
virtualStoreType: global, the package physically lives outside the consumer's repository, e.g.~/Library/pnpm/store/v11/links/@/react-use/17.6.1/<hash>/node_modules/react-use. TypeScript resolves a package's imports from where that package physically sits and ignoresNODE_PATH, soimport ... from 'react'inside the shipped.d.tsresolves to the untypedreact/index.js(silently accepted underallowJs) rather than to a declaration file:index.js, notindex.d.tsβ that is the bug. Everything those declarations feed then degrades toany, with zero compiler errors. In one real consuming app, 38 React type resolution sites coming fromreact-uselanded on JS this way.This PR adds
@types/reactas an optional peer dependency at"*", which is enough for TypeScript to find the types from the package's own location:Why it is safe
"*"β no version claim is introduced, so it resolves against whatever@types/reactthe consumer already has and cannot conflict with it. Note this repo develops against@types/react@17;"*"deliberately does not imply React 18/19 either way, matching the existing"react": "*"peer.package.jsonmetadata change only β no source, build output or API surface is touched.Precedent:
@testing-library/reactalready declares this same pair of fields for the same reason (at^18.0.0 || ^19.0.0, since it supports two React majors;react-use's ownreactpeer is*).Verified end to end on a real application: adding these peers via pnpm
packageExtensionstook it from 61 untyped + 6 unresolved React resolutions to 1012/1012 resolutions landing on.d.ts, withtscstill exiting 0.Type of change
Checklist
package.jsonmetadata only)yarn test) (unchanged; no source touched)yarn lint) (no linted source changed)yarn lint:types) (no TypeScript changed)