From f5e0bec74a9cb3bb8bfdb91c960ecd62f8a30fa5 Mon Sep 17 00:00:00 2001 From: Cole Bemis Date: Thu, 8 Apr 2021 11:50:02 -0700 Subject: [PATCH 1/5] Add as prop to ComponentProps --- src/utils/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/types.ts b/src/utils/types.ts index b68feb8c60e..444e50a42a4 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -5,12 +5,12 @@ * * @example ComponentProps */ -export type ComponentProps = T extends React.ComponentType +export type ComponentProps = (T extends React.ComponentType ? // eslint-disable-next-line @typescript-eslint/ban-types Props extends object ? Props : never - : never + : never) & {as?: React.ElementType} // This is a bandaid until we have better type support for the `as` prop /** * Contruct a type describing the items in `T`, if `T` is an array. From 089ddd03cfc7262f906bbb41db07a55499970213 Mon Sep 17 00:00:00 2001 From: Cole Bemis Date: Thu, 8 Apr 2021 12:00:42 -0700 Subject: [PATCH 2/5] Move as prop definition --- src/TextInput.tsx | 5 ++++- src/utils/types.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/TextInput.tsx b/src/TextInput.tsx index 2fc6ab1f9d1..48f61126b11 100644 --- a/src/TextInput.tsx +++ b/src/TextInput.tsx @@ -121,7 +121,10 @@ const Wrapper = styled.span` ${sx}; ` -type TextInputInternalProps = {icon?: React.ComponentType<{className?: string}>} & ComponentProps & +type TextInputInternalProps = { + as?: React.ReactElement // This is a band-aid fix until we have better type support for the `as` prop + icon?: React.ComponentType<{className?: string}> +} & ComponentProps & ComponentProps // using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input diff --git a/src/utils/types.ts b/src/utils/types.ts index 444e50a42a4..b68feb8c60e 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -5,12 +5,12 @@ * * @example ComponentProps */ -export type ComponentProps = (T extends React.ComponentType +export type ComponentProps = T extends React.ComponentType ? // eslint-disable-next-line @typescript-eslint/ban-types Props extends object ? Props : never - : never) & {as?: React.ElementType} // This is a bandaid until we have better type support for the `as` prop + : never /** * Contruct a type describing the items in `T`, if `T` is an array. From 42e21d74615b40894957b7a2badf1bddccf4c170 Mon Sep 17 00:00:00 2001 From: Cole Bemis Date: Thu, 8 Apr 2021 12:15:23 -0700 Subject: [PATCH 3/5] Update as prop type --- src/TextInput.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TextInput.tsx b/src/TextInput.tsx index 48f61126b11..81c6471c071 100644 --- a/src/TextInput.tsx +++ b/src/TextInput.tsx @@ -122,7 +122,7 @@ const Wrapper = styled.span` ` type TextInputInternalProps = { - as?: React.ReactElement // This is a band-aid fix until we have better type support for the `as` prop + as?: string | React.ComponentType // This is a band-aid fix until we have better type support for the `as` prop icon?: React.ComponentType<{className?: string}> } & ComponentProps & ComponentProps From 66e0d19628b691b83dc04f1a1b884216d327cc14 Mon Sep 17 00:00:00 2001 From: Cole Bemis Date: Thu, 8 Apr 2021 12:27:22 -0700 Subject: [PATCH 4/5] Update as prop type --- src/TextInput.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TextInput.tsx b/src/TextInput.tsx index 81c6471c071..13475236c72 100644 --- a/src/TextInput.tsx +++ b/src/TextInput.tsx @@ -122,7 +122,8 @@ const Wrapper = styled.span` ` type TextInputInternalProps = { - as?: string | React.ComponentType // This is a band-aid fix until we have better type support for the `as` prop + // eslint-disable-next-line @typescript-eslint/no-explicit-any + as?: string | React.ComponentType // This is a band-aid fix until we have better type support for the `as` prop icon?: React.ComponentType<{className?: string}> } & ComponentProps & ComponentProps From 5007661f02038f5eb778ddf7dc5a568f837dcabb Mon Sep 17 00:00:00 2001 From: Cole Bemis Date: Thu, 8 Apr 2021 12:33:39 -0700 Subject: [PATCH 5/5] Update as prop type --- src/TextInput.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TextInput.tsx b/src/TextInput.tsx index 13475236c72..816e8784485 100644 --- a/src/TextInput.tsx +++ b/src/TextInput.tsx @@ -123,7 +123,7 @@ const Wrapper = styled.span` type TextInputInternalProps = { // eslint-disable-next-line @typescript-eslint/no-explicit-any - as?: string | React.ComponentType // This is a band-aid fix until we have better type support for the `as` prop + as?: any // This is a band-aid fix until we have better type support for the `as` prop icon?: React.ComponentType<{className?: string}> } & ComponentProps & ComponentProps