From 3fca5e3045a35e4dba72dfd2716354912543a5db Mon Sep 17 00:00:00 2001 From: yoyo837 Date: Thu, 3 Dec 2026 08:14:36 +0800 Subject: [PATCH] fix: type ComponentType with React.ElementType for @types/react 16-19 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. --- src/RawItem.tsx | 9 ++++----- src/context.ts | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/RawItem.tsx b/src/RawItem.tsx index 4c09c17..4d5ad76 100644 --- a/src/RawItem.tsx +++ b/src/RawItem.tsx @@ -3,11 +3,10 @@ import { clsx } from 'clsx'; import Item from './Item'; import { OverflowContext } from './context'; -export type ComponentType = - | React.ComponentType - | React.ForwardRefExoticComponent - | React.FC - | keyof HTMLElementTagNameMap; +// `React.ReactHTML` was removed in @types/react 19, while `keyof HTMLElementTagNameMap` +// requires the consumer to include the DOM lib. `React.ElementType` covers intrinsic +// tags plus function/class/forwardRef components in every supported @types/react range. +export type ComponentType = React.ElementType; export interface RawItemProps extends React.HTMLAttributes { component?: ComponentType; diff --git a/src/context.ts b/src/context.ts index 6f0cb6d..fa2fea2 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,4 +1,4 @@ -import React from 'react'; +import * as React from 'react'; export const OverflowContext = React.createContext<{ prefixCls: string;