Skip to content

Commit 82019d6

Browse files
committed
Accept new baselines
1 parent 56520da commit 82019d6

File tree

3 files changed

+204
-1
lines changed

3 files changed

+204
-1
lines changed

tests/baselines/reference/unionAndIntersectionInference3.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,43 @@ let y1 = foo1(sx); // string
5252

5353
let x2 = foo2(sa); // unknown
5454
let y2 = foo2(sx); // { extra: number }
55+
56+
// Repro from #33490
57+
58+
declare class Component<P> { props: P }
59+
60+
export type ComponentClass<P> = new (props: P) => Component<P>;
61+
export type FunctionComponent<P> = (props: P) => null;
62+
63+
export type ComponentType<P> = FunctionComponent<P> | ComponentClass<P>;
64+
65+
export interface RouteComponentProps { route: string }
66+
67+
declare function withRouter<
68+
P extends RouteComponentProps,
69+
C extends ComponentType<P>
70+
>(
71+
component: C & ComponentType<P>
72+
): ComponentClass<Omit<P, keyof RouteComponentProps>>;
73+
74+
interface Props extends RouteComponentProps { username: string }
75+
76+
declare const MyComponent: ComponentType<Props>;
77+
78+
withRouter(MyComponent);
79+
80+
// Repro from #33490
81+
82+
type AB<T> = { a: T } | { b: T };
83+
84+
// T & AB<U> normalizes to T & { a: U } | T & { b: U } below
85+
declare function foo<T, U>(obj: T & AB<U>): [T, U];
86+
declare let ab: AB<string>;
87+
88+
let z = foo(ab); // [AB<string>, string]
5589

5690

5791
//// [unionAndIntersectionInference3.js]
58-
"use strict";
5992
// Repro from #30720
6093
concatMaybe([1, 2, 3], 4);
6194
// Repros from #32247
@@ -70,3 +103,5 @@ let x1 = foo1(sa); // string
70103
let y1 = foo1(sx); // string
71104
let x2 = foo2(sa); // unknown
72105
let y2 = foo2(sx); // { extra: number }
106+
withRouter(MyComponent);
107+
let z = foo(ab); // [AB<string>, string]

tests/baselines/reference/unionAndIntersectionInference3.symbols

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,107 @@ let y2 = foo2(sx); // { extra: number }
205205
>foo2 : Symbol(foo2, Decl(unionAndIntersectionInference3.ts, 42, 57))
206206
>sx : Symbol(sx, Decl(unionAndIntersectionInference3.ts, 46, 11))
207207

208+
// Repro from #33490
209+
210+
declare class Component<P> { props: P }
211+
>Component : Symbol(Component, Decl(unionAndIntersectionInference3.ts, 52, 18))
212+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 56, 24))
213+
>props : Symbol(Component.props, Decl(unionAndIntersectionInference3.ts, 56, 28))
214+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 56, 24))
215+
216+
export type ComponentClass<P> = new (props: P) => Component<P>;
217+
>ComponentClass : Symbol(ComponentClass, Decl(unionAndIntersectionInference3.ts, 56, 39))
218+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 58, 27))
219+
>props : Symbol(props, Decl(unionAndIntersectionInference3.ts, 58, 37))
220+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 58, 27))
221+
>Component : Symbol(Component, Decl(unionAndIntersectionInference3.ts, 52, 18))
222+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 58, 27))
223+
224+
export type FunctionComponent<P> = (props: P) => null;
225+
>FunctionComponent : Symbol(FunctionComponent, Decl(unionAndIntersectionInference3.ts, 58, 63))
226+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 59, 30))
227+
>props : Symbol(props, Decl(unionAndIntersectionInference3.ts, 59, 36))
228+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 59, 30))
229+
230+
export type ComponentType<P> = FunctionComponent<P> | ComponentClass<P>;
231+
>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54))
232+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 61, 26))
233+
>FunctionComponent : Symbol(FunctionComponent, Decl(unionAndIntersectionInference3.ts, 58, 63))
234+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 61, 26))
235+
>ComponentClass : Symbol(ComponentClass, Decl(unionAndIntersectionInference3.ts, 56, 39))
236+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 61, 26))
237+
238+
export interface RouteComponentProps { route: string }
239+
>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72))
240+
>route : Symbol(RouteComponentProps.route, Decl(unionAndIntersectionInference3.ts, 63, 38))
241+
242+
declare function withRouter<
243+
>withRouter : Symbol(withRouter, Decl(unionAndIntersectionInference3.ts, 63, 54))
244+
245+
P extends RouteComponentProps,
246+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28))
247+
>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72))
248+
249+
C extends ComponentType<P>
250+
>C : Symbol(C, Decl(unionAndIntersectionInference3.ts, 66, 32))
251+
>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54))
252+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28))
253+
254+
>(
255+
component: C & ComponentType<P>
256+
>component : Symbol(component, Decl(unionAndIntersectionInference3.ts, 68, 2))
257+
>C : Symbol(C, Decl(unionAndIntersectionInference3.ts, 66, 32))
258+
>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54))
259+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28))
260+
261+
): ComponentClass<Omit<P, keyof RouteComponentProps>>;
262+
>ComponentClass : Symbol(ComponentClass, Decl(unionAndIntersectionInference3.ts, 56, 39))
263+
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --))
264+
>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28))
265+
>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72))
266+
267+
interface Props extends RouteComponentProps { username: string }
268+
>Props : Symbol(Props, Decl(unionAndIntersectionInference3.ts, 70, 54))
269+
>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72))
270+
>username : Symbol(Props.username, Decl(unionAndIntersectionInference3.ts, 72, 45))
271+
272+
declare const MyComponent: ComponentType<Props>;
273+
>MyComponent : Symbol(MyComponent, Decl(unionAndIntersectionInference3.ts, 74, 13))
274+
>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54))
275+
>Props : Symbol(Props, Decl(unionAndIntersectionInference3.ts, 70, 54))
276+
277+
withRouter(MyComponent);
278+
>withRouter : Symbol(withRouter, Decl(unionAndIntersectionInference3.ts, 63, 54))
279+
>MyComponent : Symbol(MyComponent, Decl(unionAndIntersectionInference3.ts, 74, 13))
280+
281+
// Repro from #33490
282+
283+
type AB<T> = { a: T } | { b: T };
284+
>AB : Symbol(AB, Decl(unionAndIntersectionInference3.ts, 76, 24))
285+
>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 80, 8))
286+
>a : Symbol(a, Decl(unionAndIntersectionInference3.ts, 80, 14))
287+
>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 80, 8))
288+
>b : Symbol(b, Decl(unionAndIntersectionInference3.ts, 80, 25))
289+
>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 80, 8))
290+
291+
// T & AB<U> normalizes to T & { a: U } | T & { b: U } below
292+
declare function foo<T, U>(obj: T & AB<U>): [T, U];
293+
>foo : Symbol(foo, Decl(unionAndIntersectionInference3.ts, 80, 33))
294+
>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 83, 21))
295+
>U : Symbol(U, Decl(unionAndIntersectionInference3.ts, 83, 23))
296+
>obj : Symbol(obj, Decl(unionAndIntersectionInference3.ts, 83, 27))
297+
>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 83, 21))
298+
>AB : Symbol(AB, Decl(unionAndIntersectionInference3.ts, 76, 24))
299+
>U : Symbol(U, Decl(unionAndIntersectionInference3.ts, 83, 23))
300+
>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 83, 21))
301+
>U : Symbol(U, Decl(unionAndIntersectionInference3.ts, 83, 23))
302+
303+
declare let ab: AB<string>;
304+
>ab : Symbol(ab, Decl(unionAndIntersectionInference3.ts, 84, 11))
305+
>AB : Symbol(AB, Decl(unionAndIntersectionInference3.ts, 76, 24))
306+
307+
let z = foo(ab); // [AB<string>, string]
308+
>z : Symbol(z, Decl(unionAndIntersectionInference3.ts, 86, 3))
309+
>foo : Symbol(foo, Decl(unionAndIntersectionInference3.ts, 80, 33))
310+
>ab : Symbol(ab, Decl(unionAndIntersectionInference3.ts, 84, 11))
311+

tests/baselines/reference/unionAndIntersectionInference3.types

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,67 @@ let y2 = foo2(sx); // { extra: number }
135135
>foo2 : <T>(obj: string[] & T) => T
136136
>sx : string[] & { extra: number; }
137137

138+
// Repro from #33490
139+
140+
declare class Component<P> { props: P }
141+
>Component : Component<P>
142+
>props : P
143+
144+
export type ComponentClass<P> = new (props: P) => Component<P>;
145+
>ComponentClass : ComponentClass<P>
146+
>props : P
147+
148+
export type FunctionComponent<P> = (props: P) => null;
149+
>FunctionComponent : FunctionComponent<P>
150+
>props : P
151+
>null : null
152+
153+
export type ComponentType<P> = FunctionComponent<P> | ComponentClass<P>;
154+
>ComponentType : ComponentType<P>
155+
156+
export interface RouteComponentProps { route: string }
157+
>route : string
158+
159+
declare function withRouter<
160+
>withRouter : <P extends RouteComponentProps, C extends ComponentType<P>>(component: (C & FunctionComponent<P>) | (C & ComponentClass<P>)) => ComponentClass<Pick<P, Exclude<keyof P, "route">>>
161+
162+
P extends RouteComponentProps,
163+
C extends ComponentType<P>
164+
>(
165+
component: C & ComponentType<P>
166+
>component : (C & FunctionComponent<P>) | (C & ComponentClass<P>)
167+
168+
): ComponentClass<Omit<P, keyof RouteComponentProps>>;
169+
170+
interface Props extends RouteComponentProps { username: string }
171+
>username : string
172+
173+
declare const MyComponent: ComponentType<Props>;
174+
>MyComponent : ComponentType<Props>
175+
176+
withRouter(MyComponent);
177+
>withRouter(MyComponent) : ComponentClass<Pick<Props, "username">>
178+
>withRouter : <P extends RouteComponentProps, C extends ComponentType<P>>(component: (C & FunctionComponent<P>) | (C & ComponentClass<P>)) => ComponentClass<Pick<P, Exclude<keyof P, "route">>>
179+
>MyComponent : ComponentType<Props>
180+
181+
// Repro from #33490
182+
183+
type AB<T> = { a: T } | { b: T };
184+
>AB : AB<T>
185+
>a : T
186+
>b : T
187+
188+
// T & AB<U> normalizes to T & { a: U } | T & { b: U } below
189+
declare function foo<T, U>(obj: T & AB<U>): [T, U];
190+
>foo : <T, U>(obj: (T & { a: U; }) | (T & { b: U; })) => [T, U]
191+
>obj : (T & { a: U; }) | (T & { b: U; })
192+
193+
declare let ab: AB<string>;
194+
>ab : AB<string>
195+
196+
let z = foo(ab); // [AB<string>, string]
197+
>z : [AB<string>, string]
198+
>foo(ab) : [AB<string>, string]
199+
>foo : <T, U>(obj: (T & { a: U; }) | (T & { b: U; })) => [T, U]
200+
>ab : AB<string>
201+

0 commit comments

Comments
 (0)