Repository navigation
fix: type ComponentType with React.ElementType for @types/react 16-19 compat - #76
Conversation
… compat `ComponentType` is the public prop type of `component` / `itemComponent`. It was `keyof React.ReactHTML`, which no longer exists in @types/react 19 (error TS2694: Namespace 'React' has no exported member 'ReactHTML'), and the in-progress replacement with `keyof HTMLElementTagNameMap` requires consumers to include the DOM lib (error TS2304 otherwise). `React.ElementType` is available in @types/react 16 through 19, covers intrinsic tags as well as function / class / forwardRef components, and needs no DOM lib. Also switch `context.ts` to `import * as React from 'react'` so the emitted `context.d.ts` no longer requires `esModuleInterop` / `allowSyntheticDefaultImports` (error TS1259 for consumers that disable them). Verified the built package against @types/react 16.14 / 17.0 / 18.3 / 19.2 with and without the DOM lib and with esModuleInterop on and off.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. Walkthrough此次变更将 ChangesReact 类型与导入
Estimated code review effort: 1 (Trivial) | ~4 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
✅ Preview is ready!
↩️ Previous: ⚡️ 🤖 Powered by surge-preview |
|||||||||||||||
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #76 +/- ##
=======================================
Coverage 97.05% 97.05%
=======================================
Files 7 7
Lines 340 340
Branches 100 100
=======================================
Hits 330 330
Misses 10 10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
The TypeScript declaration compatibility changes have no active review issues.
No open issues 🎉
What changed in this PR
Improves published TypeScript declaration compatibility with React typings 16–19 and stricter consumer compiler settings.
Changes:
- Uses
React.ElementTypefor component props, avoiding a direct DOM-library dependency. - Uses a React namespace import so context declarations do not require default-import interoperability.
| File | Description |
|---|---|
src/RawItem.tsx |
Replaces the component-type union with React.ElementType and explains compatibility. |
src/context.ts |
Switches React to a namespace import. |
Review effort: Balanced

Fixes a type-level compatibility break in the published
.d.tsthat would make@rc-component/overflow@1.0.2unusable for consumers on @types/react 19 (and for consumers without the DOM lib).This is the reason the release of the already-merged
masterchanges is blocked: the currentmasterbuild type-checks fine inside the repo (which uses@types/react@19+DOM), but the emitted declarations do not type-check in a consumer project.Problems
1.
React.ReactHTMLwas removed in @types/react 19A consumer on
@types/react@19.2.xgets:masterreplaced it withkeyof HTMLElementTagNameMap, which fixes React 19 but requires the consumer to include theDOMlib:2.
context.d.tsrequiresesModuleInteropConsumers with
esModuleInterop: false/allowSyntheticDefaultImports: falsegeterror TS1259. This one predates the currentmaster, but it is the same category of problem and cheap to fix in the same pass.Changes
src/RawItem.tsx:ComponentTypeis nowReact.ElementType.React.ElementTypeexists in @types/react 16 through 19, covers intrinsic tags and function / class / forwardRef components, and does not depend on the DOM lib.ComponentTypeis only used for thecomponent/itemComponentprops, whose runtime path already passes the value straight into JSX, so this is a strictly wider and more accurate type.src/context.ts:import React from 'react'→import * as React from 'react', so the emittedcontext.d.tsuses a namespace import.Verification
Built the package with
father buildand type-checked the produced tarball in a clean consumer project (tsc --noEmit,skipLibCheck: false) across:ES2020+DOMtrue/falseES2020onlytrue/falseAll pass. The consumer test assigns an intrinsic tag, a
forwardRefcomponent, an arrow function component and a class component toComponentType, and renders<Overflow />withcomponent/itemComponent.Repo checks:
npm run tsc,npm run lint(warnings only, unchanged),npm test— 37/37 tests, 7/7 snapshots.Summary by CodeRabbit
forwardRef组件,提升不同 React 组件形式之间的类型兼容性。