feat: add optional @types/react peer dependency - #414
Open
unrevised6419 wants to merge 1 commit into
Open
unrevised6419 wants to merge 1 commit into
unrevised6419 wants to merge 1 commit into
Conversation
unrevised6419
force-pushed
the
feat/optional-types-react-peer
branch
from
September 24, 2026 03:08
3b4c798 to
466cc14
Compare
The published dist/index.d.ts imports React types, but the package only declares the react/react-dom runtime peers. Under pnpm layouts where the package lives outside the consumer's repo, TypeScript resolves that import from the package's physical location and silently falls back to the untyped react/index.js, degrading every cmdk type to any with no compiler error. Declaring @types/react as an optional peer at "^18 || ^19", mirroring the existing react peer, makes the types resolve without affecting non-TypeScript consumers or any lockfile.
unrevised6419
force-pushed
the
feat/optional-types-react-peer
branch
from
September 24, 2026 03:19
466cc14 to
e5ab1da
Compare
unrevised6419
marked this pull request as ready for review
September 24, 2026 03:28
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.
What
Adds
@types/reactas an optional peer dependency at^18 || ^19on thecmdkpackage.No runtime behaviour changes — this is metadata only.
Why
dist/index.d.tsstarts withimport * as React from 'react', but the package declares only thereact/react-domruntime peers. TypeScript resolves a package's imports from where that package physically sits on disk, and it ignoresNODE_PATH.That is fine in a classic
node_moduleslayout, where the consumer's@types/reactis reachable by walking up. It breaks under pnpm'svirtualStoreType: global, wherecmdklives outside the consumer's repository entirely, e.g.~/Library/pnpm/store/v11/links/…/node_modules/cmdk. From there,reacthas no types to resolve to, so TS falls back to the untypedreact/index.js(silently accepted withallowJs: true) or fails to resolve at all.tsc --noEmit --traceResolutionin a consumer usingmoduleResolution: "bundler"with@types/reactinstalled:index.js, notindex.d.ts. EveryReact.*type in cmdk's declarations —React.ReactNode, theComponentPropsWithoutRefbases forCommand,Command.Input,Command.Item, the ref types — degrades toany, and the compiler reports nothing. Consumers lose autocomplete and prop checking on cmdk without any signal that it happened. That silence is what makes it worth fixing.With the optional peer declared, pnpm links
@types/reactnext to the package and the same trace resolves to@types/react/index.d.ts.Why it is safe
^18 || ^19— it mirrors the existingreactpeer, so consumers on either major are covered and nothing new is installed for anyone who does not already have the types.This repo develops against
@types/react18 while the runtime peer allows^18 || ^19; the types peer mirrors that union rather than narrowing it to 18.Precedent
@testing-library/reactdeclares exactly this pair, for exactly this reason.Verification
Measured on a real application by applying the same peers through pnpm
packageExtensions: the app went from 61 untyped + 6 unresolved React resolutions to 1012/1012 landing on.d.ts, withtscstill exiting 0.