From 82019d616dc8a56290d1b22b5d32cd12598c214e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 20 Oct 2019 18:01:41 -0700 Subject: [PATCH] Accept new baselines --- .../unionAndIntersectionInference3.js | 37 ++++++- .../unionAndIntersectionInference3.symbols | 104 ++++++++++++++++++ .../unionAndIntersectionInference3.types | 64 +++++++++++ 3 files changed, 204 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/unionAndIntersectionInference3.js b/tests/baselines/reference/unionAndIntersectionInference3.js index 415d98220a..12ce5a9a19 100644 --- a/tests/baselines/reference/unionAndIntersectionInference3.js +++ b/tests/baselines/reference/unionAndIntersectionInference3.js @@ -52,10 +52,43 @@ let y1 = foo1(sx); // string let x2 = foo2(sa); // unknown let y2 = foo2(sx); // { extra: number } + +// Repro from #33490 + +declare class Component

{ props: P } + +export type ComponentClass

= new (props: P) => Component

; +export type FunctionComponent

= (props: P) => null; + +export type ComponentType

= FunctionComponent

| ComponentClass

; + +export interface RouteComponentProps { route: string } + +declare function withRouter< + P extends RouteComponentProps, + C extends ComponentType

+>( + component: C & ComponentType

+): ComponentClass>; + +interface Props extends RouteComponentProps { username: string } + +declare const MyComponent: ComponentType; + +withRouter(MyComponent); + +// Repro from #33490 + +type AB = { a: T } | { b: T }; + +// T & AB normalizes to T & { a: U } | T & { b: U } below +declare function foo(obj: T & AB): [T, U]; +declare let ab: AB; + +let z = foo(ab); // [AB, string] //// [unionAndIntersectionInference3.js] -"use strict"; // Repro from #30720 concatMaybe([1, 2, 3], 4); // Repros from #32247 @@ -70,3 +103,5 @@ let x1 = foo1(sa); // string let y1 = foo1(sx); // string let x2 = foo2(sa); // unknown let y2 = foo2(sx); // { extra: number } +withRouter(MyComponent); +let z = foo(ab); // [AB, string] diff --git a/tests/baselines/reference/unionAndIntersectionInference3.symbols b/tests/baselines/reference/unionAndIntersectionInference3.symbols index 1d237951b4..43079f9e8a 100644 --- a/tests/baselines/reference/unionAndIntersectionInference3.symbols +++ b/tests/baselines/reference/unionAndIntersectionInference3.symbols @@ -205,3 +205,107 @@ let y2 = foo2(sx); // { extra: number } >foo2 : Symbol(foo2, Decl(unionAndIntersectionInference3.ts, 42, 57)) >sx : Symbol(sx, Decl(unionAndIntersectionInference3.ts, 46, 11)) +// Repro from #33490 + +declare class Component

{ props: P } +>Component : Symbol(Component, Decl(unionAndIntersectionInference3.ts, 52, 18)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 56, 24)) +>props : Symbol(Component.props, Decl(unionAndIntersectionInference3.ts, 56, 28)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 56, 24)) + +export type ComponentClass

= new (props: P) => Component

; +>ComponentClass : Symbol(ComponentClass, Decl(unionAndIntersectionInference3.ts, 56, 39)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 58, 27)) +>props : Symbol(props, Decl(unionAndIntersectionInference3.ts, 58, 37)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 58, 27)) +>Component : Symbol(Component, Decl(unionAndIntersectionInference3.ts, 52, 18)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 58, 27)) + +export type FunctionComponent

= (props: P) => null; +>FunctionComponent : Symbol(FunctionComponent, Decl(unionAndIntersectionInference3.ts, 58, 63)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 59, 30)) +>props : Symbol(props, Decl(unionAndIntersectionInference3.ts, 59, 36)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 59, 30)) + +export type ComponentType

= FunctionComponent

| ComponentClass

; +>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 61, 26)) +>FunctionComponent : Symbol(FunctionComponent, Decl(unionAndIntersectionInference3.ts, 58, 63)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 61, 26)) +>ComponentClass : Symbol(ComponentClass, Decl(unionAndIntersectionInference3.ts, 56, 39)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 61, 26)) + +export interface RouteComponentProps { route: string } +>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72)) +>route : Symbol(RouteComponentProps.route, Decl(unionAndIntersectionInference3.ts, 63, 38)) + +declare function withRouter< +>withRouter : Symbol(withRouter, Decl(unionAndIntersectionInference3.ts, 63, 54)) + + P extends RouteComponentProps, +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28)) +>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72)) + + C extends ComponentType

+>C : Symbol(C, Decl(unionAndIntersectionInference3.ts, 66, 32)) +>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28)) + +>( + component: C & ComponentType

+>component : Symbol(component, Decl(unionAndIntersectionInference3.ts, 68, 2)) +>C : Symbol(C, Decl(unionAndIntersectionInference3.ts, 66, 32)) +>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28)) + +): ComponentClass>; +>ComponentClass : Symbol(ComponentClass, Decl(unionAndIntersectionInference3.ts, 56, 39)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28)) +>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72)) + +interface Props extends RouteComponentProps { username: string } +>Props : Symbol(Props, Decl(unionAndIntersectionInference3.ts, 70, 54)) +>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72)) +>username : Symbol(Props.username, Decl(unionAndIntersectionInference3.ts, 72, 45)) + +declare const MyComponent: ComponentType; +>MyComponent : Symbol(MyComponent, Decl(unionAndIntersectionInference3.ts, 74, 13)) +>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54)) +>Props : Symbol(Props, Decl(unionAndIntersectionInference3.ts, 70, 54)) + +withRouter(MyComponent); +>withRouter : Symbol(withRouter, Decl(unionAndIntersectionInference3.ts, 63, 54)) +>MyComponent : Symbol(MyComponent, Decl(unionAndIntersectionInference3.ts, 74, 13)) + +// Repro from #33490 + +type AB = { a: T } | { b: T }; +>AB : Symbol(AB, Decl(unionAndIntersectionInference3.ts, 76, 24)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 80, 8)) +>a : Symbol(a, Decl(unionAndIntersectionInference3.ts, 80, 14)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 80, 8)) +>b : Symbol(b, Decl(unionAndIntersectionInference3.ts, 80, 25)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 80, 8)) + +// T & AB normalizes to T & { a: U } | T & { b: U } below +declare function foo(obj: T & AB): [T, U]; +>foo : Symbol(foo, Decl(unionAndIntersectionInference3.ts, 80, 33)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 83, 21)) +>U : Symbol(U, Decl(unionAndIntersectionInference3.ts, 83, 23)) +>obj : Symbol(obj, Decl(unionAndIntersectionInference3.ts, 83, 27)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 83, 21)) +>AB : Symbol(AB, Decl(unionAndIntersectionInference3.ts, 76, 24)) +>U : Symbol(U, Decl(unionAndIntersectionInference3.ts, 83, 23)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 83, 21)) +>U : Symbol(U, Decl(unionAndIntersectionInference3.ts, 83, 23)) + +declare let ab: AB; +>ab : Symbol(ab, Decl(unionAndIntersectionInference3.ts, 84, 11)) +>AB : Symbol(AB, Decl(unionAndIntersectionInference3.ts, 76, 24)) + +let z = foo(ab); // [AB, string] +>z : Symbol(z, Decl(unionAndIntersectionInference3.ts, 86, 3)) +>foo : Symbol(foo, Decl(unionAndIntersectionInference3.ts, 80, 33)) +>ab : Symbol(ab, Decl(unionAndIntersectionInference3.ts, 84, 11)) + diff --git a/tests/baselines/reference/unionAndIntersectionInference3.types b/tests/baselines/reference/unionAndIntersectionInference3.types index fb50747432..05cb9368f8 100644 --- a/tests/baselines/reference/unionAndIntersectionInference3.types +++ b/tests/baselines/reference/unionAndIntersectionInference3.types @@ -135,3 +135,67 @@ let y2 = foo2(sx); // { extra: number } >foo2 : (obj: string[] & T) => T >sx : string[] & { extra: number; } +// Repro from #33490 + +declare class Component

{ props: P } +>Component : Component

+>props : P + +export type ComponentClass

= new (props: P) => Component

; +>ComponentClass : ComponentClass

+>props : P + +export type FunctionComponent

= (props: P) => null; +>FunctionComponent : FunctionComponent

+>props : P +>null : null + +export type ComponentType

= FunctionComponent

| ComponentClass

; +>ComponentType : ComponentType

+ +export interface RouteComponentProps { route: string } +>route : string + +declare function withRouter< +>withRouter :

>(component: (C & FunctionComponent

) | (C & ComponentClass

)) => ComponentClass>> + + P extends RouteComponentProps, + C extends ComponentType

+>( + component: C & ComponentType

+>component : (C & FunctionComponent

) | (C & ComponentClass

) + +): ComponentClass>; + +interface Props extends RouteComponentProps { username: string } +>username : string + +declare const MyComponent: ComponentType; +>MyComponent : ComponentType + +withRouter(MyComponent); +>withRouter(MyComponent) : ComponentClass> +>withRouter :

>(component: (C & FunctionComponent

) | (C & ComponentClass

)) => ComponentClass>> +>MyComponent : ComponentType + +// Repro from #33490 + +type AB = { a: T } | { b: T }; +>AB : AB +>a : T +>b : T + +// T & AB normalizes to T & { a: U } | T & { b: U } below +declare function foo(obj: T & AB): [T, U]; +>foo : (obj: (T & { a: U; }) | (T & { b: U; })) => [T, U] +>obj : (T & { a: U; }) | (T & { b: U; }) + +declare let ab: AB; +>ab : AB + +let z = foo(ab); // [AB, string] +>z : [AB, string] +>foo(ab) : [AB, string] +>foo : (obj: (T & { a: U; }) | (T & { b: U; })) => [T, U] +>ab : AB +