Skip to content

Commit d066cb2

Browse files
committed
Accept new baselines
1 parent 065c199 commit d066cb2

14 files changed

Lines changed: 1092 additions & 7 deletions
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
//// [tests/cases/compiler/genericCallInferenceInConditionalTypes1.ts] ////
2+
3+
=== genericCallInferenceInConditionalTypes1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/59937
5+
6+
type Ref<T> = {
7+
>Ref : Symbol(Ref, Decl(genericCallInferenceInConditionalTypes1.ts, 0, 0))
8+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 2, 9))
9+
10+
current: T;
11+
>current : Symbol(current, Decl(genericCallInferenceInConditionalTypes1.ts, 2, 15))
12+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 2, 9))
13+
14+
};
15+
16+
type FunctionComponent<P> = (props: P) => unknown;
17+
>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2))
18+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 23))
19+
>props : Symbol(props, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 29))
20+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 23))
21+
22+
type ComponentProps<T extends FunctionComponent<any>> =
23+
>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50))
24+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 8, 20))
25+
>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2))
26+
27+
T extends FunctionComponent<infer P> ? P : {};
28+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 8, 20))
29+
>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2))
30+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 9, 35))
31+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 9, 35))
32+
33+
type PropsWithoutRef<P> = P extends any
34+
>PropsWithoutRef : Symbol(PropsWithoutRef, Decl(genericCallInferenceInConditionalTypes1.ts, 9, 48))
35+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21))
36+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21))
37+
38+
? "ref" extends keyof P
39+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21))
40+
41+
? Omit<P, "ref">
42+
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --))
43+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21))
44+
45+
: P
46+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21))
47+
48+
: P;
49+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21))
50+
51+
type ComponentPropsWithoutRef<T extends FunctionComponent<any>> =
52+
>ComponentPropsWithoutRef : Symbol(ComponentPropsWithoutRef, Decl(genericCallInferenceInConditionalTypes1.ts, 15, 6))
53+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 17, 30))
54+
>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2))
55+
56+
PropsWithoutRef<ComponentProps<T>>;
57+
>PropsWithoutRef : Symbol(PropsWithoutRef, Decl(genericCallInferenceInConditionalTypes1.ts, 9, 48))
58+
>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50))
59+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 17, 30))
60+
61+
declare function forwardRef<T, P>(
62+
>forwardRef : Symbol(forwardRef, Decl(genericCallInferenceInConditionalTypes1.ts, 18, 37))
63+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 28))
64+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 30))
65+
66+
component: (props: P, ref: Ref<T>) => unknown,
67+
>component : Symbol(component, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 34))
68+
>props : Symbol(props, Decl(genericCallInferenceInConditionalTypes1.ts, 21, 14))
69+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 30))
70+
>ref : Symbol(ref, Decl(genericCallInferenceInConditionalTypes1.ts, 21, 23))
71+
>Ref : Symbol(Ref, Decl(genericCallInferenceInConditionalTypes1.ts, 0, 0))
72+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 28))
73+
74+
): (props: P & { ref?: Ref<T> }) => unknown;
75+
>props : Symbol(props, Decl(genericCallInferenceInConditionalTypes1.ts, 22, 4))
76+
>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 30))
77+
>ref : Symbol(ref, Decl(genericCallInferenceInConditionalTypes1.ts, 22, 16))
78+
>Ref : Symbol(Ref, Decl(genericCallInferenceInConditionalTypes1.ts, 0, 0))
79+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 28))
80+
81+
const ComponentWithForwardRef = forwardRef(
82+
>ComponentWithForwardRef : Symbol(ComponentWithForwardRef, Decl(genericCallInferenceInConditionalTypes1.ts, 24, 5))
83+
>forwardRef : Symbol(forwardRef, Decl(genericCallInferenceInConditionalTypes1.ts, 18, 37))
84+
85+
<T extends FunctionComponent<any>>(
86+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 25, 3))
87+
>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2))
88+
89+
props: ComponentPropsWithoutRef<T>,
90+
>props : Symbol(props, Decl(genericCallInferenceInConditionalTypes1.ts, 25, 37))
91+
>ComponentPropsWithoutRef : Symbol(ComponentPropsWithoutRef, Decl(genericCallInferenceInConditionalTypes1.ts, 15, 6))
92+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 25, 3))
93+
94+
ref: Ref<HTMLElement>,
95+
>ref : Symbol(ref, Decl(genericCallInferenceInConditionalTypes1.ts, 26, 39))
96+
>Ref : Symbol(Ref, Decl(genericCallInferenceInConditionalTypes1.ts, 0, 0))
97+
>HTMLElement : Symbol(HTMLElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
98+
99+
) => {
100+
return null;
101+
},
102+
);
103+
104+
type Test<T> = T extends { component?: infer Component }
105+
>Test : Symbol(Test, Decl(genericCallInferenceInConditionalTypes1.ts, 31, 2))
106+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 10))
107+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 10))
108+
>component : Symbol(component, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 26))
109+
>Component : Symbol(Component, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 44))
110+
111+
? Component extends FunctionComponent<any>
112+
>Component : Symbol(Component, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 44))
113+
>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2))
114+
115+
? ComponentProps<Component>
116+
>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50))
117+
>Component : Symbol(Component, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 44))
118+
119+
: never
120+
: never;
121+
122+
// the first one here has a chance to pollute the cache
123+
type Result1 = ComponentProps<typeof ComponentWithForwardRef>;
124+
>Result1 : Symbol(Result1, Decl(genericCallInferenceInConditionalTypes1.ts, 37, 10))
125+
>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50))
126+
>ComponentWithForwardRef : Symbol(ComponentWithForwardRef, Decl(genericCallInferenceInConditionalTypes1.ts, 24, 5))
127+
128+
// that could be incorrectly reused by this one
129+
type Result2 = Test<{ component: typeof ComponentWithForwardRef }>; // no `T` leak
130+
>Result2 : Symbol(Result2, Decl(genericCallInferenceInConditionalTypes1.ts, 40, 62))
131+
>Test : Symbol(Test, Decl(genericCallInferenceInConditionalTypes1.ts, 31, 2))
132+
>component : Symbol(component, Decl(genericCallInferenceInConditionalTypes1.ts, 42, 21))
133+
>ComponentWithForwardRef : Symbol(ComponentWithForwardRef, Decl(genericCallInferenceInConditionalTypes1.ts, 24, 5))
134+
135+
// same as ComponentWithForwardRef above but using a resolved signature instead of a direct inferred result of `forwardRef`
136+
declare const ComponentWithForwardRef2: <T extends FunctionComponent<any>>(
137+
>ComponentWithForwardRef2 : Symbol(ComponentWithForwardRef2, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 13))
138+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 41))
139+
>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2))
140+
141+
props: PropsWithoutRef<ComponentProps<T>> & {
142+
>props : Symbol(props, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 75))
143+
>PropsWithoutRef : Symbol(PropsWithoutRef, Decl(genericCallInferenceInConditionalTypes1.ts, 9, 48))
144+
>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50))
145+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 41))
146+
147+
className?: string;
148+
>className : Symbol(className, Decl(genericCallInferenceInConditionalTypes1.ts, 46, 47))
149+
150+
as?: T | undefined;
151+
>as : Symbol(as, Decl(genericCallInferenceInConditionalTypes1.ts, 47, 23))
152+
>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 41))
153+
154+
} & {
155+
ref?: Ref<HTMLElement> | undefined;
156+
>ref : Symbol(ref, Decl(genericCallInferenceInConditionalTypes1.ts, 49, 7))
157+
>Ref : Symbol(Ref, Decl(genericCallInferenceInConditionalTypes1.ts, 0, 0))
158+
>HTMLElement : Symbol(HTMLElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
159+
160+
},
161+
) => unknown;
162+
163+
type Result3 = ComponentProps<typeof ComponentWithForwardRef2>;
164+
>Result3 : Symbol(Result3, Decl(genericCallInferenceInConditionalTypes1.ts, 52, 13))
165+
>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50))
166+
>ComponentWithForwardRef2 : Symbol(ComponentWithForwardRef2, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 13))
167+
168+
type Result4 = Test<{ component: typeof ComponentWithForwardRef2 }>;
169+
>Result4 : Symbol(Result4, Decl(genericCallInferenceInConditionalTypes1.ts, 54, 63))
170+
>Test : Symbol(Test, Decl(genericCallInferenceInConditionalTypes1.ts, 31, 2))
171+
>component : Symbol(component, Decl(genericCallInferenceInConditionalTypes1.ts, 55, 21))
172+
>ComponentWithForwardRef2 : Symbol(ComponentWithForwardRef2, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 13))
173+
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
//// [tests/cases/compiler/genericCallInferenceInConditionalTypes1.ts] ////
2+
3+
=== genericCallInferenceInConditionalTypes1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/59937
5+
6+
type Ref<T> = {
7+
>Ref : Ref<T>
8+
> : ^^^^^^
9+
10+
current: T;
11+
>current : T
12+
> : ^
13+
14+
};
15+
16+
type FunctionComponent<P> = (props: P) => unknown;
17+
>FunctionComponent : FunctionComponent<P>
18+
> : ^^^^^^^^^^^^^^^^^^^^
19+
>props : P
20+
> : ^
21+
22+
type ComponentProps<T extends FunctionComponent<any>> =
23+
>ComponentProps : ComponentProps<T>
24+
> : ^^^^^^^^^^^^^^^^^
25+
26+
T extends FunctionComponent<infer P> ? P : {};
27+
28+
type PropsWithoutRef<P> = P extends any
29+
>PropsWithoutRef : PropsWithoutRef<P>
30+
> : ^^^^^^^^^^^^^^^^^^
31+
32+
? "ref" extends keyof P
33+
? Omit<P, "ref">
34+
: P
35+
: P;
36+
37+
type ComponentPropsWithoutRef<T extends FunctionComponent<any>> =
38+
>ComponentPropsWithoutRef : ComponentPropsWithoutRef<T>
39+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
40+
41+
PropsWithoutRef<ComponentProps<T>>;
42+
43+
declare function forwardRef<T, P>(
44+
>forwardRef : <T, P>(component: (props: P, ref: Ref<T>) => unknown) => (props: P & { ref?: Ref<T>; }) => unknown
45+
> : ^ ^^ ^^ ^^ ^^^^^
46+
47+
component: (props: P, ref: Ref<T>) => unknown,
48+
>component : (props: P, ref: Ref<T>) => unknown
49+
> : ^ ^^ ^^ ^^ ^^^^^
50+
>props : P
51+
> : ^
52+
>ref : Ref<T>
53+
> : ^^^^^^
54+
55+
): (props: P & { ref?: Ref<T> }) => unknown;
56+
>props : P & { ref?: Ref<T>; }
57+
> : ^^^^^^^^^^^^ ^^^
58+
>ref : Ref<T> | undefined
59+
> : ^^^^^^^^^^^^^^^^^^
60+
61+
const ComponentWithForwardRef = forwardRef(
62+
>ComponentWithForwardRef : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }) => unknown
63+
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
64+
>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
65+
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66+
>forwardRef : <T, P>(component: (props: P, ref: Ref<T>) => unknown) => (props: P & { ref?: Ref<T>; }) => unknown
67+
> : ^ ^^ ^^ ^^ ^^^^^
68+
69+
<T extends FunctionComponent<any>>(
70+
><T extends FunctionComponent<any>>( props: ComponentPropsWithoutRef<T>, ref: Ref<HTMLElement>, ) => { return null; } : <T extends FunctionComponent<any>>(props: ComponentPropsWithoutRef<T>, ref: Ref<HTMLElement>) => null
71+
> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^
72+
73+
props: ComponentPropsWithoutRef<T>,
74+
>props : PropsWithoutRef<ComponentProps<T>>
75+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76+
77+
ref: Ref<HTMLElement>,
78+
>ref : Ref<HTMLElement>
79+
> : ^^^^^^^^^^^^^^^^
80+
81+
) => {
82+
return null;
83+
},
84+
);
85+
86+
type Test<T> = T extends { component?: infer Component }
87+
>Test : Test<T>
88+
> : ^^^^^^^
89+
>component : Component | undefined
90+
> : ^^^^^^^^^^^^^^^^^^^^^
91+
92+
? Component extends FunctionComponent<any>
93+
? ComponentProps<Component>
94+
: never
95+
: never;
96+
97+
// the first one here has a chance to pollute the cache
98+
type Result1 = ComponentProps<typeof ComponentWithForwardRef>;
99+
>Result1 : Omit<any, "ref"> & { ref?: Ref<HTMLElement> | undefined; }
100+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101+
>ComponentWithForwardRef : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }) => unknown
102+
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103+
104+
// that could be incorrectly reused by this one
105+
type Result2 = Test<{ component: typeof ComponentWithForwardRef }>; // no `T` leak
106+
>Result2 : Omit<any, "ref"> & { ref?: Ref<HTMLElement> | undefined; }
107+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
108+
>component : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }) => unknown
109+
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110+
>ComponentWithForwardRef : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }) => unknown
111+
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112+
113+
// same as ComponentWithForwardRef above but using a resolved signature instead of a direct inferred result of `forwardRef`
114+
declare const ComponentWithForwardRef2: <T extends FunctionComponent<any>>(
115+
>ComponentWithForwardRef2 : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { className?: string; as?: T | undefined; } & { ref?: Ref<HTMLElement> | undefined; }) => unknown
116+
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
117+
118+
props: PropsWithoutRef<ComponentProps<T>> & {
119+
>props : PropsWithoutRef<ComponentProps<T>> & { className?: string; as?: T | undefined; } & { ref?: Ref<HTMLElement> | undefined; }
120+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^ ^^^^^^^^^^^^^^ ^^^
121+
122+
className?: string;
123+
>className : string | undefined
124+
> : ^^^^^^^^^^^^^^^^^^
125+
126+
as?: T | undefined;
127+
>as : T | undefined
128+
> : ^^^^^^^^^^^^^
129+
130+
} & {
131+
ref?: Ref<HTMLElement> | undefined;
132+
>ref : Ref<HTMLElement> | undefined
133+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
134+
135+
},
136+
) => unknown;
137+
138+
type Result3 = ComponentProps<typeof ComponentWithForwardRef2>;
139+
>Result3 : Omit<any, "ref"> & { className?: string; as?: FunctionComponent<any> | undefined; } & { ref?: Ref<HTMLElement> | undefined; }
140+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
141+
>ComponentWithForwardRef2 : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { className?: string; as?: T | undefined; } & { ref?: Ref<HTMLElement> | undefined; }) => unknown
142+
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
143+
144+
type Result4 = Test<{ component: typeof ComponentWithForwardRef2 }>;
145+
>Result4 : Omit<any, "ref"> & { className?: string; as?: FunctionComponent<any> | undefined; } & { ref?: Ref<HTMLElement> | undefined; }
146+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
147+
>component : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { className?: string; as?: T | undefined; } & { ref?: Ref<HTMLElement> | undefined; }) => unknown
148+
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
149+
>ComponentWithForwardRef2 : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { className?: string; as?: T | undefined; } & { ref?: Ref<HTMLElement> | undefined; }) => unknown
150+
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
151+

0 commit comments

Comments
 (0)