Skip to content

fix: type ComponentType with React.ElementType for @types/react 16-19 compat - #76

Merged
zombieJ merged 1 commit into
masterfrom
fix/component-type-react19-compat
Dec 3, 2026
Merged

zombieJ merged 1 commit into
masterfrom
fix/component-type-react19-compat

Conversation

@yoyo837

@yoyo837 yoyo837 commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Fixes a type-level compatibility break in the published .d.ts that would make @rc-component/overflow@1.0.2 unusable for consumers on @types/react 19 (and for consumers without the DOM lib).

This is the reason the release of the already-merged master changes is blocked: the current master build 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.ReactHTML was removed in @types/react 19

// lib/RawItem.d.ts (published 1.0.1)
export type ComponentType = ... | keyof React.ReactHTML;

A consumer on @types/react@19.2.x gets:

node_modules/@rc-component/overflow/lib/RawItem.d.ts(2,123): error TS2694:
  Namespace 'React' has no exported member 'ReactHTML'.

master replaced it with keyof HTMLElementTagNameMap, which fixes React 19 but requires the consumer to include the DOM lib:

node_modules/@rc-component/overflow/lib/RawItem.d.ts(2,117): error TS2304:
  Cannot find name 'HTMLElementTagNameMap'.

2. context.d.ts requires esModuleInterop

// lib/context.d.ts
import React from 'react';

Consumers with esModuleInterop: false / allowSyntheticDefaultImports: false get error TS1259. This one predates the current master, but it is the same category of problem and cheap to fix in the same pass.

Changes

  • src/RawItem.tsx: ComponentType is now React.ElementType.

    React.ElementType exists in @types/react 16 through 19, covers intrinsic tags and function / class / forwardRef components, and does not depend on the DOM lib. ComponentType is only used for the component / itemComponent props, 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 emitted context.d.ts uses a namespace import.

Verification

Built the package with father build and type-checked the produced tarball in a clean consumer project (tsc --noEmit, skipLibCheck: false) across:

@types/react lib esModuleInterop
16.14.60 / 17.0.83 / 18.3.28 / 19.2.17 ES2020 + DOM true / false
16.14.60 / 17.0.83 / 18.3.28 / 19.2.17 ES2020 only true / false

All pass. The consumer test assigns an intrinsic tag, a forwardRef component, an arrow function component and a class component to ComponentType, and renders <Overflow /> with component / itemComponent.

Repo checks: npm run tsc, npm run lint (warnings only, unchanged), npm test — 37/37 tests, 7/7 snapshots.

Summary by CodeRabbit

  • 兼容性改进
    • 更新了可用于相关组件的类型支持,涵盖内置 HTML 标签以及函数、类和 forwardRef 组件,提升不同 React 组件形式之间的类型兼容性。
    • 此次调整针对类型声明,不改变现有界面或运行时行为。

… 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.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 00:14
@vercel

vercel Bot commented Dec 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
overflow Error Error Dec 3, 2026 12:15am UTC

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

此次变更将 ComponentType 改为 React.ElementType,并将 src/context.ts 中的 React 默认导入改为命名空间导入。

Changes

React 类型与导入

Layer / File(s) Summary
组件类型与 React 导入
src/RawItem.tsx, src/context.ts
ComponentType 改为 React.ElementType,并新增类型范围与兼容性说明。src/context.ts 将 React 默认导入改为命名空间导入。

Estimated code review effort: 1 (Trivial) | ~4 minutes

Change: Bug fix

Suggested reviewers: muxinfeng, afc163

Merge Risk: Minimal · up to 3fca5

This change loosens the ComponentType prop type for compatibility with React 16 through 19 types and switches an import to the namespace form. No concrete regression was found. The only open item is a Vercel preview deployment failure that is not linked to these edits.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: type ComponentType with React.ElementType for @types/react 16-19 compat”与主要变更一致。变更将 src/RawItem.tsx 中的 ComponentType 改为 React.ElementType,并将 src/context.ts 的默认导入改为命名空间导入,目的是兼容 @types/react 16 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

标题“fix: type ComponentType with React.ElementType for @types/react 16-19 compat”与主要变更一致。变更将 src/RawItem.tsx 中的 ComponentType 改为 React.ElementType,并将 src/context.ts 的默认导入改为命名空间导入,目的是兼容 @types/react 16 至 19。标题简洁,指出了核心修改点。

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

小兔看见类型换新装
ElementType 把标签与组件收进框
React 命名空间也已登场
注释写明类型范围与兼容方向
小兔轻轻合上代码本
耳朵摇摇,跳向月光

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0c179f73-05ba-40c9-affe-5d31f0454f3b
Commits

Reviewing files that changed from the base of the PR and between f1c801c and 3fca5e3.

Files selected for processing: 2

  • src/RawItem.tsx
  • src/context.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 3fca5e3.

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

✅ Preview is ready!

PR preview ✅ Ready ✅ Ready
🔗 Preview https://react-component-overflow-preview-pr-76.surge.sh
📝 Commit3fca5e3
⏱️ Build time17.629s
📦 Size1.9 MB · 45 files
🪵 LogsView logs
📱 MobileScan to open preview on mobile

↩️ Previous: ⚡️ 3fca5e3 · react-component-overflow-preview-pr-76.surge.sh (open ↗) · 2026-12-03 00:15:33 UTC

🤖 Powered by surge-preview

@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.05%. Comparing base (f1c801c) to head (3fca5e3).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.ElementType for 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

@zombieJ
zombieJ merged commit b523f48 into master Dec 3, 2026
19 of 20 checks passed

This branch had an error being deployed

1 failed deployment
Preview — 3fca5e30 Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants