From 961404d5cc956fba3e29fbfd203453c9441a99b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B1=E3=82=A4=E3=83=A9?= Date: Sat, 18 Jan 2025 08:35:52 -0700 Subject: [PATCH] replace `keyof ReactSVG` with `SVGElementType` (#2668) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * replace `keyof ReactSVG` with `SVGElementType` * define `SVGElementType` locally * 🧹 * update comments * Format types.ts * Update types.ts * Update types.ts --------- Co-authored-by: Eric Fennis --- .../src/createLucideIcon.ts | 8 +------- packages/lucide-react-native/src/types.ts | 19 +++++++++++++++++-- packages/lucide-react/src/types.ts | 19 +++++++++++++++++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/packages/lucide-react-native/src/createLucideIcon.ts b/packages/lucide-react-native/src/createLucideIcon.ts index 9eb27bd97..51c044789 100644 --- a/packages/lucide-react-native/src/createLucideIcon.ts +++ b/packages/lucide-react-native/src/createLucideIcon.ts @@ -1,10 +1,4 @@ -import { - forwardRef, - createElement, - ReactSVG, - FunctionComponent, - ForwardRefExoticComponent, -} from 'react'; +import { forwardRef, createElement, FunctionComponent } from 'react'; import * as NativeSvg from 'react-native-svg'; import defaultAttributes, { childDefaultAttributes } from './defaultAttributes'; import { IconNode, LucideIcon, LucideProps } from './types'; diff --git a/packages/lucide-react-native/src/types.ts b/packages/lucide-react-native/src/types.ts index fd534414a..c7427bf4f 100644 --- a/packages/lucide-react-native/src/types.ts +++ b/packages/lucide-react-native/src/types.ts @@ -1,7 +1,22 @@ -import type { ForwardRefExoticComponent, ReactSVG } from 'react'; +import type { ForwardRefExoticComponent } from 'react'; import type { SvgProps } from 'react-native-svg'; -export type IconNode = [elementName: keyof ReactSVG, attrs: Record][]; +/** + * A reduced version of `SVGElementType` from @types/react. This type was added + * with the release of React 19, and is included here in order to support usage + * with older versions. + */ +type SVGElementType = + | 'circle' + | 'ellipse' + | 'g' + | 'line' + | 'path' + | 'polygon' + | 'polyline' + | 'rect'; + +export type IconNode = [elementName: SVGElementType, attrs: Record][]; export interface LucideProps extends SvgProps { size?: string | number; diff --git a/packages/lucide-react/src/types.ts b/packages/lucide-react/src/types.ts index ed686b315..f57229224 100644 --- a/packages/lucide-react/src/types.ts +++ b/packages/lucide-react/src/types.ts @@ -1,6 +1,21 @@ -import { ReactSVG, SVGProps, ForwardRefExoticComponent, RefAttributes } from 'react'; +import type { SVGProps, ForwardRefExoticComponent, RefAttributes } from 'react'; -export type IconNode = [elementName: keyof ReactSVG, attrs: Record][]; +/** + * A reduced version of `SVGElementType` from @types/react. This type was added + * with the release of React 19, and is included here in order to support usage + * with older versions. + */ +type SVGElementType = + | 'circle' + | 'ellipse' + | 'g' + | 'line' + | 'path' + | 'polygon' + | 'polyline' + | 'rect'; + +export type IconNode = [elementName: SVGElementType, attrs: Record][]; export type SVGAttributes = Partial>; type ElementAttributes = RefAttributes & SVGAttributes;