-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.d.ts
65 lines (55 loc) · 1.65 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/// <reference types="react" />
// Block external access to auxiliary types
export {};
type Merge<T, U> = Omit<T, keyof U> & U;
type PropsWithAs<P, T extends React.ElementType> = P & { as?: T };
export type PolymorphicPropsWithoutRef<P, T extends React.ElementType> = Merge<
T extends keyof JSX.IntrinsicElements
? React.PropsWithoutRef<JSX.IntrinsicElements[T]>
: React.ComponentPropsWithoutRef<T>,
PropsWithAs<P, T>
>;
export type PolymorphicPropsWithRef<P, T extends React.ElementType> = Merge<
T extends keyof JSX.IntrinsicElements
? React.PropsWithRef<JSX.IntrinsicElements[T]>
: React.ComponentPropsWithRef<T>,
PropsWithAs<P, T>
>;
// TODO:
// - PolymorphicFunctionComponent
// - PolymorphicVoidFunctionComponent (requires @types/react >=16.9.48)
type PolymorphicExoticComponent<
P = {},
T extends React.ElementType = React.ElementType,
> = Merge<
React.ExoticComponent<P & { [key: string]: unknown }>,
{
/**
* **NOTE**: Exotic components are not callable.
*/
<InstanceT extends React.ElementType = T>(
props: PolymorphicPropsWithRef<P, InstanceT>,
): React.ReactElement | null;
}
>;
export type PolymorphicForwardRefExoticComponent<
P,
T extends React.ElementType,
> = Merge<
React.ForwardRefExoticComponent<P & { [key: string]: unknown }>,
PolymorphicExoticComponent<P, T>
>;
export type PolymorphicMemoExoticComponent<
P,
T extends React.ElementType,
> = Merge<
React.MemoExoticComponent<React.ComponentType<any>>,
PolymorphicExoticComponent<P, T>
>;
export type PolymorphicLazyExoticComponent<
P,
T extends React.ElementType,
> = Merge<
React.LazyExoticComponent<React.ComponentType<any>>,
PolymorphicExoticComponent<P, T>
>;