From 1c9fe44726535ad15ca742a6521eea8a0eec3475 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 10 Feb 2019 15:29:22 -0800 Subject: [PATCH] Accept new baselines --- .../unionAndIntersectionInference1.js | 28 ++++++++- .../unionAndIntersectionInference1.symbols | 58 ++++++++++++++++++- .../unionAndIntersectionInference1.types | 53 +++++++++++++++++ 3 files changed, 136 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/unionAndIntersectionInference1.js b/tests/baselines/reference/unionAndIntersectionInference1.js index 235eb23ebf8..ca9e527d99e 100644 --- a/tests/baselines/reference/unionAndIntersectionInference1.js +++ b/tests/baselines/reference/unionAndIntersectionInference1.js @@ -71,6 +71,24 @@ declare var mbp: Man & Bear; pigify(mbp).oinks; // OK, mbp is treated as Pig pigify(mbp).walks; // Ok, mbp is treated as Man + +// Repros from #29815 + +interface ITest { + name: 'test' +} + +const createTestAsync = (): Promise => Promise.resolve().then(() => ({ name: 'test' })) + +const createTest = (): ITest => { + return { name: 'test' } +} + +declare function f1(x: T | U): T | U; +declare function f2(x: T & U): T & U; + +let x1: string = f1('a'); +let x2: string = f2('a'); //// [unionAndIntersectionInference1.js] @@ -80,7 +98,7 @@ function destructure(something, haveValue, haveY) { return something === y ? haveY(y) : haveValue(something); } var value = Math.random() > 0.5 ? 'hey!' : undefined; -var result = destructure(value, function (text) { return 'string'; }, function (y) { return 'other one'; }); // text: string, y: Y +var result = destructure(value, text => 'string', y => 'other one'); // text: string, y: Y // Repro from #4212 function isVoid(value) { return undefined; @@ -107,7 +125,13 @@ function baz1(value) { function get(x) { return null; // just an example } -var foo; +let foo; get(foo).toUpperCase(); // Ok pigify(mbp).oinks; // OK, mbp is treated as Pig pigify(mbp).walks; // Ok, mbp is treated as Man +const createTestAsync = () => Promise.resolve().then(() => ({ name: 'test' })); +const createTest = () => { + return { name: 'test' }; +}; +let x1 = f1('a'); +let x2 = f2('a'); diff --git a/tests/baselines/reference/unionAndIntersectionInference1.symbols b/tests/baselines/reference/unionAndIntersectionInference1.symbols index 38bcd416dff..e866f19daa4 100644 --- a/tests/baselines/reference/unionAndIntersectionInference1.symbols +++ b/tests/baselines/reference/unionAndIntersectionInference1.symbols @@ -50,7 +50,7 @@ function destructure( var value = Math.random() > 0.5 ? 'hey!' : undefined; >value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 12, 3)) >Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) ->Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) >Y : Symbol(Y, Decl(unionAndIntersectionInference1.ts, 0, 0)) >undefined : Symbol(undefined) @@ -201,3 +201,59 @@ pigify(mbp).walks; // Ok, mbp is treated as Man >mbp : Symbol(mbp, Decl(unionAndIntersectionInference1.ts, 68, 11)) >walks : Symbol(Man.walks, Decl(unionAndIntersectionInference1.ts, 55, 15)) +// Repros from #29815 + +interface ITest { +>ITest : Symbol(ITest, Decl(unionAndIntersectionInference1.ts, 71, 18)) + + name: 'test' +>name : Symbol(ITest.name, Decl(unionAndIntersectionInference1.ts, 75, 17)) +} + +const createTestAsync = (): Promise => Promise.resolve().then(() => ({ name: 'test' })) +>createTestAsync : Symbol(createTestAsync, Decl(unionAndIntersectionInference1.ts, 79, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>ITest : Symbol(ITest, Decl(unionAndIntersectionInference1.ts, 71, 18)) +>Promise.resolve().then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>name : Symbol(name, Decl(unionAndIntersectionInference1.ts, 79, 77)) + +const createTest = (): ITest => { +>createTest : Symbol(createTest, Decl(unionAndIntersectionInference1.ts, 81, 5)) +>ITest : Symbol(ITest, Decl(unionAndIntersectionInference1.ts, 71, 18)) + + return { name: 'test' } +>name : Symbol(name, Decl(unionAndIntersectionInference1.ts, 82, 10)) +} + +declare function f1(x: T | U): T | U; +>f1 : Symbol(f1, Decl(unionAndIntersectionInference1.ts, 83, 1)) +>T : Symbol(T, Decl(unionAndIntersectionInference1.ts, 85, 20)) +>U : Symbol(U, Decl(unionAndIntersectionInference1.ts, 85, 22)) +>x : Symbol(x, Decl(unionAndIntersectionInference1.ts, 85, 26)) +>T : Symbol(T, Decl(unionAndIntersectionInference1.ts, 85, 20)) +>U : Symbol(U, Decl(unionAndIntersectionInference1.ts, 85, 22)) +>T : Symbol(T, Decl(unionAndIntersectionInference1.ts, 85, 20)) +>U : Symbol(U, Decl(unionAndIntersectionInference1.ts, 85, 22)) + +declare function f2(x: T & U): T & U; +>f2 : Symbol(f2, Decl(unionAndIntersectionInference1.ts, 85, 43)) +>T : Symbol(T, Decl(unionAndIntersectionInference1.ts, 86, 20)) +>U : Symbol(U, Decl(unionAndIntersectionInference1.ts, 86, 22)) +>x : Symbol(x, Decl(unionAndIntersectionInference1.ts, 86, 26)) +>T : Symbol(T, Decl(unionAndIntersectionInference1.ts, 86, 20)) +>U : Symbol(U, Decl(unionAndIntersectionInference1.ts, 86, 22)) +>T : Symbol(T, Decl(unionAndIntersectionInference1.ts, 86, 20)) +>U : Symbol(U, Decl(unionAndIntersectionInference1.ts, 86, 22)) + +let x1: string = f1('a'); +>x1 : Symbol(x1, Decl(unionAndIntersectionInference1.ts, 88, 3)) +>f1 : Symbol(f1, Decl(unionAndIntersectionInference1.ts, 83, 1)) + +let x2: string = f2('a'); +>x2 : Symbol(x2, Decl(unionAndIntersectionInference1.ts, 89, 3)) +>f2 : Symbol(f2, Decl(unionAndIntersectionInference1.ts, 85, 43)) + diff --git a/tests/baselines/reference/unionAndIntersectionInference1.types b/tests/baselines/reference/unionAndIntersectionInference1.types index 7b2515c6b58..4dddcb8bd0f 100644 --- a/tests/baselines/reference/unionAndIntersectionInference1.types +++ b/tests/baselines/reference/unionAndIntersectionInference1.types @@ -179,3 +179,56 @@ pigify(mbp).walks; // Ok, mbp is treated as Man >mbp : Man & Bear >walks : boolean +// Repros from #29815 + +interface ITest { + name: 'test' +>name : "test" +} + +const createTestAsync = (): Promise => Promise.resolve().then(() => ({ name: 'test' })) +>createTestAsync : () => Promise +>(): Promise => Promise.resolve().then(() => ({ name: 'test' })) : () => Promise +>Promise.resolve().then(() => ({ name: 'test' })) : Promise +>Promise.resolve().then : (onfulfilled?: (value: void) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Promise.resolve() : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>then : (onfulfilled?: (value: void) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>() => ({ name: 'test' }) : () => { name: "test"; } +>({ name: 'test' }) : { name: "test"; } +>{ name: 'test' } : { name: "test"; } +>name : "test" +>'test' : "test" + +const createTest = (): ITest => { +>createTest : () => ITest +>(): ITest => { return { name: 'test' }} : () => ITest + + return { name: 'test' } +>{ name: 'test' } : { name: "test"; } +>name : "test" +>'test' : "test" +} + +declare function f1(x: T | U): T | U; +>f1 : (x: T | U) => T | U +>x : T | U + +declare function f2(x: T & U): T & U; +>f2 : (x: T & U) => T & U +>x : T & U + +let x1: string = f1('a'); +>x1 : string +>f1('a') : "a" +>f1 : (x: T | U) => T | U +>'a' : "a" + +let x2: string = f2('a'); +>x2 : string +>f2('a') : "a" +>f2 : (x: T & U) => T & U +>'a' : "a" +