forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenericCallInferenceInConditionalTypes1.types
More file actions
151 lines (119 loc) · 8.32 KB
/
genericCallInferenceInConditionalTypes1.types
File metadata and controls
151 lines (119 loc) · 8.32 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//// [tests/cases/compiler/genericCallInferenceInConditionalTypes1.ts] ////
=== genericCallInferenceInConditionalTypes1.ts ===
// https://github.com/microsoft/TypeScript/issues/59937
type Ref<T> = {
>Ref : Ref<T>
> : ^^^^^^
current: T;
>current : T
> : ^
};
type FunctionComponent<P> = (props: P) => unknown;
>FunctionComponent : FunctionComponent<P>
> : ^^^^^^^^^^^^^^^^^^^^
>props : P
> : ^
type ComponentProps<T extends FunctionComponent<any>> =
>ComponentProps : ComponentProps<T>
> : ^^^^^^^^^^^^^^^^^
T extends FunctionComponent<infer P> ? P : {};
type PropsWithoutRef<P> = P extends any
>PropsWithoutRef : PropsWithoutRef<P>
> : ^^^^^^^^^^^^^^^^^^
? "ref" extends keyof P
? Omit<P, "ref">
: P
: P;
type ComponentPropsWithoutRef<T extends FunctionComponent<any>> =
>ComponentPropsWithoutRef : ComponentPropsWithoutRef<T>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
PropsWithoutRef<ComponentProps<T>>;
declare function forwardRef<T, P>(
>forwardRef : <T, P>(component: (props: P, ref: Ref<T>) => unknown) => (props: P & { ref?: Ref<T>; }) => unknown
> : ^ ^^ ^^ ^^ ^^^^^
component: (props: P, ref: Ref<T>) => unknown,
>component : (props: P, ref: Ref<T>) => unknown
> : ^ ^^ ^^ ^^ ^^^^^
>props : P
> : ^
>ref : Ref<T>
> : ^^^^^^
): (props: P & { ref?: Ref<T> }) => unknown;
>props : P & { ref?: Ref<T>; }
> : ^^^^^^^^^^^^ ^^^
>ref : Ref<T> | undefined
> : ^^^^^^^^^^^^^^^^^^
const ComponentWithForwardRef = forwardRef(
>ComponentWithForwardRef : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>forwardRef( <T extends FunctionComponent<any>>( props: ComponentPropsWithoutRef<T>, ref: Ref<HTMLElement>, ) => { return null; },) : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>forwardRef : <T, P>(component: (props: P, ref: Ref<T>) => unknown) => (props: P & { ref?: Ref<T>; }) => unknown
> : ^ ^^ ^^ ^^ ^^^^^
<T extends FunctionComponent<any>>(
><T extends FunctionComponent<any>>( props: ComponentPropsWithoutRef<T>, ref: Ref<HTMLElement>, ) => { return null; } : <T extends FunctionComponent<any>>(props: ComponentPropsWithoutRef<T>, ref: Ref<HTMLElement>) => null
> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^
props: ComponentPropsWithoutRef<T>,
>props : PropsWithoutRef<ComponentProps<T>>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ref: Ref<HTMLElement>,
>ref : Ref<HTMLElement>
> : ^^^^^^^^^^^^^^^^
) => {
return null;
},
);
type Test<T> = T extends { component?: infer Component }
>Test : Test<T>
> : ^^^^^^^
>component : Component | undefined
> : ^^^^^^^^^^^^^^^^^^^^^
? Component extends FunctionComponent<any>
? ComponentProps<Component>
: never
: never;
// the first one here has a chance to pollute the cache
type Result1 = ComponentProps<typeof ComponentWithForwardRef>;
>Result1 : Omit<any, "ref"> & { ref?: Ref<HTMLElement> | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>ComponentWithForwardRef : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// that could be incorrectly reused by this one
type Result2 = Test<{ component: typeof ComponentWithForwardRef }>; // no `T` leak
>Result2 : PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>component : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>ComponentWithForwardRef : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// same as ComponentWithForwardRef above but using a resolved signature instead of a direct inferred result of `forwardRef`
declare const ComponentWithForwardRef2: <T extends FunctionComponent<any>>(
>ComponentWithForwardRef2 : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { className?: string; as?: T | undefined; } & { ref?: Ref<HTMLElement> | undefined; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
props: PropsWithoutRef<ComponentProps<T>> & {
>props : PropsWithoutRef<ComponentProps<T>> & { className?: string; as?: T | undefined; } & { ref?: Ref<HTMLElement> | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^ ^^^^^^^^^^^^^^ ^^^
className?: string;
>className : string | undefined
> : ^^^^^^^^^^^^^^^^^^
as?: T | undefined;
>as : T | undefined
> : ^^^^^^^^^^^^^
} & {
ref?: Ref<HTMLElement> | undefined;
>ref : Ref<HTMLElement> | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
},
) => unknown;
type Result3 = ComponentProps<typeof ComponentWithForwardRef2>;
>Result3 : Omit<any, "ref"> & { className?: string; as?: FunctionComponent<any> | undefined; } & { ref?: Ref<HTMLElement> | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>ComponentWithForwardRef2 : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { className?: string; as?: T | undefined; } & { ref?: Ref<HTMLElement> | undefined; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
type Result4 = Test<{ component: typeof ComponentWithForwardRef2 }>;
>Result4 : Omit<any, "ref"> & { className?: string; as?: FunctionComponent<any> | undefined; } & { ref?: Ref<HTMLElement> | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>component : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { className?: string; as?: T | undefined; } & { ref?: Ref<HTMLElement> | undefined; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
>ComponentWithForwardRef2 : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { className?: string; as?: T | undefined; } & { ref?: Ref<HTMLElement> | undefined; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^