fix: declare @types/react as an optional peerDependency - #230
fix: declare @types/react as an optional peerDependency#230jiwooIncludeJeong wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 22935d9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@jiwooIncludeJeong is attempting to deploy a commit to the Toss Team on Vercel. A member of the Team first needs to authorize it. |
| "vitest": "^2.1.8" | ||
| }, | ||
| "peerDependencies": { | ||
| "@types/react": "*", |
There was a problem hiding this comment.
Is there a specific reason why the peer dependency version for @types/react is set to *?
How about setting it to "^16.8 || ^17 || ^18 || ^19" to align with the actual runtime versions required by React?
Packages like base-ui also use explicit version specifications instead of *.
https://github.com/mui/base-ui/blob/master/packages/react/package.json#L148
There was a problem hiding this comment.
There is no specific reason! I will edit it and re-request review soon! Thanks!
There was a problem hiding this comment.
feat: specify @types/react version i commited the changes!
Summary
overlay-kitexposes React types in its public API (the bundleddist/index.d.tsimportsFCfromreactand re-exportsreact/jsx-runtime), but it only declaresreactas a peer dependency — not@types/react. As a result, in strict / isolated installs (pnpm, Yarn PnP) consumers' TypeScript cannot resolve the React typings thatoverlay-kit's declarations depend on, and the entire public API silently collapses toany.This PR adds
@types/reactas an optional peer dependency so the types resolve correctly for TypeScript consumers, while not affecting JavaScript-only users.Root cause
overlay-kit/dist/index.d.tsdoes:With pnpm's isolated node_modules, the overlay-kit package directory only has the declared react runtime peer linked — @types/react is not reachable from overlay-kit's module-resolution ancestry. TypeScript therefore resolves the bare react import to React's typeless runtime index.js, so:
Consumers then lose all type safety, e.g.:
and Parameters[0] resolves to unknown.
This is masked under npm / Yarn Classic because their flat hoisting accidentally places
@types/reactat the top level where overlay-kit's declarations can reach it. It is a genuine missing declaration that strict package managers correctly surface.Fix
This matches the standard pattern used across the React + TypeScript ecosystem (e.g. @radix-ui/*, framer-motion) for libraries that expose React types publicly.
Reproduction
pnpm add overlay-kit @types/react
Impact
요약
overlay-kit은 public API에 React 타입을 노출합니다 (배포되는dist/index.d.ts가react의FC를 import하고react/jsx-runtime을 재노출). 하지만 peer dependency로는react만 선언하고@types/react는 선언하지 않습니다. 그 결과 엄격/격리 설치 환경(pnpm, Yarn PnP)에서는 소비자의 TypeScript가overlay-kit선언이 의존하는 React 타입을 해석하지 못하고,any로 추론되게 됩니다.이 PR은
@types/react를 optional peer dependency로 추가해, TypeScript 소비자에서 타입이 정상 해석되도록 하고 JavaScript 전용 사용자에게는 영향을 주지 않습니다.근본 원인
overlay-kit/dist/index.d.ts:pnpm의 격리된 node_modules에서는 overlay-kit 패키지 디렉토리에 선언된 react 런타임 peer만 링크되고, @types/react overlay-kit의 모듈 해석 조상 경로에서 닿지 않습니다. 따라서 TypeScript는 react import를 타입이 없는 런타임 index.js로 해석하고:
소비자는 타입 안전성을 모두 잃습니다:
Parameters[0]도 unknown으로 해석됩니다.
npm / Yarn Classic에서는 flat hoisting이 @types/react를 top-level에 올려서 우연히 해석되기 때문에 가려질 뿐, 실제로는 누락된 선언입니다. 패키지 매니저가 이를 정확히 드러냅니다.
수정
이는 React 타입을 public하게 노출하는 라이브러리(@radix-ui/*, framer-motion 등)가 쓰는 표준 패턴과 동일합니다.