From 6dfcbffdc15015dc23a15a9d227c544a3b750cd5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 8 Feb 2018 17:15:00 -0800 Subject: [PATCH] Accept new baselines --- .../reference/conditionalTypes1.errors.txt | 35 +++++- .../baselines/reference/conditionalTypes1.js | 52 ++++++++ .../reference/conditionalTypes1.symbols | 110 +++++++++++++++++ .../reference/conditionalTypes1.types | 112 ++++++++++++++++++ 4 files changed, 308 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/conditionalTypes1.errors.txt b/tests/baselines/reference/conditionalTypes1.errors.txt index 4f515876b1e..8b42f006cd4 100644 --- a/tests/baselines/reference/conditionalTypes1.errors.txt +++ b/tests/baselines/reference/conditionalTypes1.errors.txt @@ -58,9 +58,10 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(156,5): error TS2 tests/cases/conformance/types/conditional/conditionalTypes1.ts(157,5): error TS2322: Type 'T' is not assignable to type 'ZeroOf'. Type 'string | number' is not assignable to type 'ZeroOf'. Type 'string' is not assignable to type 'ZeroOf'. +tests/cases/conformance/types/conditional/conditionalTypes1.ts(247,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'Foo'. -==== tests/cases/conformance/types/conditional/conditionalTypes1.ts (18 errors) ==== +==== tests/cases/conformance/types/conditional/conditionalTypes1.ts (19 errors) ==== type Diff = T extends U ? never : T; type Filter = T extends U ? T : never; type NonNullable = Diff; @@ -364,4 +365,36 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(157,5): error TS2 type T81 = Eq2; // false type T82 = Eq2; // false type T83 = Eq2; // true + + // Repro from #21756 + + type Foo = T extends string ? boolean : number; + type Bar = T extends string ? boolean : number; + const convert = (value: Foo): Bar => value; + + type Baz = Foo; + const convert2 = (value: Foo): Baz => value; + + function f31() { + type T1 = T extends string ? boolean : number; + type T2 = T extends string ? boolean : number; + var x: T1; + var x: T2; + } + + function f32() { + type T1 = T & U extends string ? boolean : number; + type T2 = Foo; + var z: T1; + var z: T2; // Error, T2 is distributive, T1 isn't + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'Foo'. + } + + function f33() { + type T1 = Foo; + type T2 = Bar; + var z: T1; + var z: T2; + } \ No newline at end of file diff --git a/tests/baselines/reference/conditionalTypes1.js b/tests/baselines/reference/conditionalTypes1.js index 3ca5966ce8e..403259b049f 100644 --- a/tests/baselines/reference/conditionalTypes1.js +++ b/tests/baselines/reference/conditionalTypes1.js @@ -224,6 +224,36 @@ type T80 = Eq2; // true type T81 = Eq2; // false type T82 = Eq2; // false type T83 = Eq2; // true + +// Repro from #21756 + +type Foo = T extends string ? boolean : number; +type Bar = T extends string ? boolean : number; +const convert = (value: Foo): Bar => value; + +type Baz = Foo; +const convert2 = (value: Foo): Baz => value; + +function f31() { + type T1 = T extends string ? boolean : number; + type T2 = T extends string ? boolean : number; + var x: T1; + var x: T2; +} + +function f32() { + type T1 = T & U extends string ? boolean : number; + type T2 = Foo; + var z: T1; + var z: T2; // Error, T2 is distributive, T1 isn't +} + +function f33() { + type T1 = Foo; + type T2 = Bar; + var z: T1; + var z: T2; +} //// [conditionalTypes1.js] @@ -285,6 +315,20 @@ function f21(x, y) { x = y; // Error y = x; // Error } +var convert = function (value) { return value; }; +var convert2 = function (value) { return value; }; +function f31() { + var x; + var x; +} +function f32() { + var z; + var z; // Error, T2 is distributive, T1 isn't +} +function f33() { + var z; + var z; +} //// [conditionalTypes1.d.ts] @@ -450,3 +494,11 @@ declare type T80 = Eq2; declare type T81 = Eq2; declare type T82 = Eq2; declare type T83 = Eq2; +declare type Foo = T extends string ? boolean : number; +declare type Bar = T extends string ? boolean : number; +declare const convert: (value: Foo) => Foo; +declare type Baz = Foo; +declare const convert2: (value: Foo) => Foo; +declare function f31(): void; +declare function f32(): void; +declare function f33(): void; diff --git a/tests/baselines/reference/conditionalTypes1.symbols b/tests/baselines/reference/conditionalTypes1.symbols index 276c1af740a..883a2d9bda1 100644 --- a/tests/baselines/reference/conditionalTypes1.symbols +++ b/tests/baselines/reference/conditionalTypes1.symbols @@ -852,3 +852,113 @@ type T83 = Eq2; // true >T83 : Symbol(T83, Decl(conditionalTypes1.ts, 223, 28)) >Eq2 : Symbol(Eq2, Decl(conditionalTypes1.ts, 218, 29)) +// Repro from #21756 + +type Foo = T extends string ? boolean : number; +>Foo : Symbol(Foo, Decl(conditionalTypes1.ts, 224, 29)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 228, 9)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 228, 9)) + +type Bar = T extends string ? boolean : number; +>Bar : Symbol(Bar, Decl(conditionalTypes1.ts, 228, 50)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 229, 9)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 229, 9)) + +const convert = (value: Foo): Bar => value; +>convert : Symbol(convert, Decl(conditionalTypes1.ts, 230, 5)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 230, 17)) +>value : Symbol(value, Decl(conditionalTypes1.ts, 230, 20)) +>Foo : Symbol(Foo, Decl(conditionalTypes1.ts, 224, 29)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 230, 17)) +>Bar : Symbol(Bar, Decl(conditionalTypes1.ts, 228, 50)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 230, 17)) +>value : Symbol(value, Decl(conditionalTypes1.ts, 230, 20)) + +type Baz = Foo; +>Baz : Symbol(Baz, Decl(conditionalTypes1.ts, 230, 52)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 232, 9)) +>Foo : Symbol(Foo, Decl(conditionalTypes1.ts, 224, 29)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 232, 9)) + +const convert2 = (value: Foo): Baz => value; +>convert2 : Symbol(convert2, Decl(conditionalTypes1.ts, 233, 5)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 233, 18)) +>value : Symbol(value, Decl(conditionalTypes1.ts, 233, 21)) +>Foo : Symbol(Foo, Decl(conditionalTypes1.ts, 224, 29)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 233, 18)) +>Baz : Symbol(Baz, Decl(conditionalTypes1.ts, 230, 52)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 233, 18)) +>value : Symbol(value, Decl(conditionalTypes1.ts, 233, 21)) + +function f31() { +>f31 : Symbol(f31, Decl(conditionalTypes1.ts, 233, 53)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 235, 13)) + + type T1 = T extends string ? boolean : number; +>T1 : Symbol(T1, Decl(conditionalTypes1.ts, 235, 19)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 235, 13)) + + type T2 = T extends string ? boolean : number; +>T2 : Symbol(T2, Decl(conditionalTypes1.ts, 236, 50)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 235, 13)) + + var x: T1; +>x : Symbol(x, Decl(conditionalTypes1.ts, 238, 7), Decl(conditionalTypes1.ts, 239, 7)) +>T1 : Symbol(T1, Decl(conditionalTypes1.ts, 235, 19)) + + var x: T2; +>x : Symbol(x, Decl(conditionalTypes1.ts, 238, 7), Decl(conditionalTypes1.ts, 239, 7)) +>T2 : Symbol(T2, Decl(conditionalTypes1.ts, 236, 50)) +} + +function f32() { +>f32 : Symbol(f32, Decl(conditionalTypes1.ts, 240, 1)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 242, 13)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 242, 15)) + + type T1 = T & U extends string ? boolean : number; +>T1 : Symbol(T1, Decl(conditionalTypes1.ts, 242, 22)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 242, 13)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 242, 15)) + + type T2 = Foo; +>T2 : Symbol(T2, Decl(conditionalTypes1.ts, 243, 54)) +>Foo : Symbol(Foo, Decl(conditionalTypes1.ts, 224, 29)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 242, 13)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 242, 15)) + + var z: T1; +>z : Symbol(z, Decl(conditionalTypes1.ts, 245, 7), Decl(conditionalTypes1.ts, 246, 7)) +>T1 : Symbol(T1, Decl(conditionalTypes1.ts, 242, 22)) + + var z: T2; // Error, T2 is distributive, T1 isn't +>z : Symbol(z, Decl(conditionalTypes1.ts, 245, 7), Decl(conditionalTypes1.ts, 246, 7)) +>T2 : Symbol(T2, Decl(conditionalTypes1.ts, 243, 54)) +} + +function f33() { +>f33 : Symbol(f33, Decl(conditionalTypes1.ts, 247, 1)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 249, 13)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 249, 15)) + + type T1 = Foo; +>T1 : Symbol(T1, Decl(conditionalTypes1.ts, 249, 22)) +>Foo : Symbol(Foo, Decl(conditionalTypes1.ts, 224, 29)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 249, 13)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 249, 15)) + + type T2 = Bar; +>T2 : Symbol(T2, Decl(conditionalTypes1.ts, 250, 25)) +>Bar : Symbol(Bar, Decl(conditionalTypes1.ts, 228, 50)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 249, 13)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 249, 15)) + + var z: T1; +>z : Symbol(z, Decl(conditionalTypes1.ts, 252, 7), Decl(conditionalTypes1.ts, 253, 7)) +>T1 : Symbol(T1, Decl(conditionalTypes1.ts, 249, 22)) + + var z: T2; +>z : Symbol(z, Decl(conditionalTypes1.ts, 252, 7), Decl(conditionalTypes1.ts, 253, 7)) +>T2 : Symbol(T2, Decl(conditionalTypes1.ts, 250, 25)) +} + diff --git a/tests/baselines/reference/conditionalTypes1.types b/tests/baselines/reference/conditionalTypes1.types index e8a50e60fcc..9c68f394094 100644 --- a/tests/baselines/reference/conditionalTypes1.types +++ b/tests/baselines/reference/conditionalTypes1.types @@ -991,3 +991,115 @@ type T83 = Eq2; // true >false : false >false : false +// Repro from #21756 + +type Foo = T extends string ? boolean : number; +>Foo : Foo +>T : T +>T : T + +type Bar = T extends string ? boolean : number; +>Bar : Bar +>T : T +>T : T + +const convert = (value: Foo): Bar => value; +>convert : (value: Foo) => Foo +>(value: Foo): Bar => value : (value: Foo) => Foo +>U : U +>value : Foo +>Foo : Foo +>U : U +>Bar : Bar +>U : U +>value : Foo + +type Baz = Foo; +>Baz : Foo +>T : T +>Foo : Foo +>T : T + +const convert2 = (value: Foo): Baz => value; +>convert2 : (value: Foo) => Foo +>(value: Foo): Baz => value : (value: Foo) => Foo +>T : T +>value : Foo +>Foo : Foo +>T : T +>Baz : Foo +>T : T +>value : Foo + +function f31() { +>f31 : () => void +>T : T + + type T1 = T extends string ? boolean : number; +>T1 : T extends string ? boolean : number +>T : T + + type T2 = T extends string ? boolean : number; +>T2 : T extends string ? boolean : number +>T : T + + var x: T1; +>x : T extends string ? boolean : number +>T1 : T extends string ? boolean : number + + var x: T2; +>x : T extends string ? boolean : number +>T2 : T extends string ? boolean : number +} + +function f32() { +>f32 : () => void +>T : T +>U : U + + type T1 = T & U extends string ? boolean : number; +>T1 : T & U extends string ? boolean : number +>T : T +>U : U + + type T2 = Foo; +>T2 : Foo +>Foo : Foo +>T : T +>U : U + + var z: T1; +>z : T & U extends string ? boolean : number +>T1 : T & U extends string ? boolean : number + + var z: T2; // Error, T2 is distributive, T1 isn't +>z : T & U extends string ? boolean : number +>T2 : Foo +} + +function f33() { +>f33 : () => void +>T : T +>U : U + + type T1 = Foo; +>T1 : Foo +>Foo : Foo +>T : T +>U : U + + type T2 = Bar; +>T2 : Foo +>Bar : Bar +>T : T +>U : U + + var z: T1; +>z : Foo +>T1 : Foo + + var z: T2; +>z : Foo +>T2 : Foo +} +