Skip to content

Commit 7327989

Browse files
committed
fix: types
1 parent 51ab544 commit 7327989

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

src/components/Select.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
useInteractions,
1616
useListNavigation,
1717
useRole,
18-
useTypeahead
18+
useTypeahead,
1919
} from '@floating-ui/react-dom-interactions'
2020
import { IconChevronDown } from '@tabler/icons-react'
2121
import { AnimatePresence, motion } from 'framer-motion'
@@ -27,9 +27,10 @@ import React, {
2727
useImperativeHandle,
2828
useLayoutEffect,
2929
useRef,
30-
useState
30+
useState,
3131
} from 'react'
3232
import { PP, PR } from '../types/PolymorphicElementProps'
33+
import { Timeout } from '../types/Timeout'
3334
import { forwardRefWithGenerics } from '../utils/ref'
3435
import { cssClickable, cssDisablable } from '../utils/styles'
3536
import { ListItem, ListItemProps } from './$List'
@@ -116,7 +117,7 @@ export const Select = forwardRefWithGenerics(
116117
const listContentRef = useRef<Array<string | null>>([])
117118
const allowSelectRef = useRef(false)
118119
const allowMouseUpRef = useRef(true)
119-
const selectTimeoutRef = useRef<any>()
120+
const selectTimeoutRef = useRef<Timeout>()
120121

121122
const [open, setOpen] = useState(false)
122123
const [selectedIndex, setSelectedIndex] = useState(0)

src/components/TextField.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,18 @@ export const TextField: PC<'input', TextFieldProps> = forwardRefWithGenerics(
5050
multiline = false,
5151
disabled = false,
5252
resizable = false,
53-
as,
53+
// TODO types are wrong when `as` is inferred by variant
54+
as = multiline ? 'textarea' : 'input',
5455
...rest
5556
} = props
5657

57-
// TODO types are wrong when `as` is inferred by variant
58-
const calculatedAs = as || (multiline ? 'textarea' : 'input')
59-
6058
return (
6159
<TextFieldContainer
6260
fullWidth={fullWidth}
6361
disabled={disabled}
6462
resizable={getResizable(resizable)}
6563
ref={ref}
66-
as={calculatedAs}
64+
as={as}
6765
{...rest}
6866
/>
6967
)

src/types/PolymorphicElementProps.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, {
22
ComponentPropsWithoutRef,
33
ComponentPropsWithRef,
44
ElementType,
5-
JSXElementConstructor
5+
JSXElementConstructor,
66
} from 'react'
77

88
// from: https://codesandbox.io/s/9dxyq?file=/src/PolymorphicComponent.tsx
@@ -16,10 +16,15 @@ type PropsOf<
1616
C extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>
1717
> = JSX.LibraryManagedAttributes<C, ComponentPropsWithoutRef<C>>
1818

19+
// https://github.com/microsoft/TypeScript/issues/44596#issuecomment-1447648600
20+
21+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22+
type OmitFix<T> = T extends any ? T : never
23+
1924
type ExtendableProps<
2025
ExtendedProps = Record<string, unknown>,
2126
OverrideProps = Record<string, unknown>
22-
> = OverrideProps & Omit<ExtendedProps, keyof OverrideProps>
27+
> = OverrideProps & OmitFix<Omit<ExtendedProps, keyof OverrideProps>>
2328

2429
type InheritableElementProps<
2530
C extends ElementType,

src/types/Timeout.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2+
export type Timeout = any // null | ReturnType<typeof setTimeout>

src/utils/ref.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/ban-types */
12
import React, { ForwardedRef, ReactElement, RefAttributes } from 'react'
23

34
export const forwardRefWithGenerics: <T, P = {}>(

0 commit comments

Comments
 (0)