diff --git a/tests/baselines/reference/bestCommonTypeReturnStatement.types b/tests/baselines/reference/bestCommonTypeReturnStatement.types index 31f72ab93b4..a8b435c8a27 100644 --- a/tests/baselines/reference/bestCommonTypeReturnStatement.types +++ b/tests/baselines/reference/bestCommonTypeReturnStatement.types @@ -15,7 +15,7 @@ interface IPromise { } function f() { ->f : () => IPromise +>f : () => IPromise if (true) return b(); >true : boolean diff --git a/tests/baselines/reference/functionImplementationErrors.errors.txt b/tests/baselines/reference/functionImplementationErrors.errors.txt index dc5ad5a2747..224ebc7c08e 100644 --- a/tests/baselines/reference/functionImplementationErrors.errors.txt +++ b/tests/baselines/reference/functionImplementationErrors.errors.txt @@ -1,44 +1,26 @@ -tests/cases/conformance/functions/functionImplementationErrors.ts(3,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/functions/functionImplementationErrors.ts(7,19): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/functions/functionImplementationErrors.ts(11,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/functions/functionImplementationErrors.ts(17,10): error TS2354: No best common type exists among return expressions. tests/cases/conformance/functions/functionImplementationErrors.ts(26,16): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. tests/cases/conformance/functions/functionImplementationErrors.ts(31,17): error TS2373: Initializer of parameter 'n' cannot reference identifier 'm' declared after it. tests/cases/conformance/functions/functionImplementationErrors.ts(36,17): error TS2373: Initializer of parameter 'n' cannot reference identifier 'm' declared after it. -tests/cases/conformance/functions/functionImplementationErrors.ts(50,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/functions/functionImplementationErrors.ts(54,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/functions/functionImplementationErrors.ts(58,11): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/functions/functionImplementationErrors.ts(62,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/functions/functionImplementationErrors.ts(66,11): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/functions/functionImplementationErrors.ts(70,11): error TS2354: No best common type exists among return expressions. -==== tests/cases/conformance/functions/functionImplementationErrors.ts (13 errors) ==== +==== tests/cases/conformance/functions/functionImplementationErrors.ts (3 errors) ==== // FunctionExpression with no return type annotation with multiple return statements with unrelated types var f1 = function () { - ~~~~~~~~ -!!! error TS2354: No best common type exists among return expressions. return ''; return 3; }; var f2 = function x() { - ~ -!!! error TS2354: No best common type exists among return expressions. return ''; return 3; }; var f3 = () => { - ~~~~~~~ -!!! error TS2354: No best common type exists among return expressions. return ''; return 3; }; // FunctionExpression with no return type annotation with return branch of number[] and other of string[] var f4 = function () { - ~~~~~~~~ -!!! error TS2354: No best common type exists among return expressions. if (true) { return ['']; } else { @@ -78,38 +60,26 @@ tests/cases/conformance/functions/functionImplementationErrors.ts(70,11): error class Derived1 extends Base { private m; } class Derived2 extends Base { private n; } function f8() { - ~~ -!!! error TS2354: No best common type exists among return expressions. return new Derived1(); return new Derived2(); } var f9 = function () { - ~~~~~~~~ -!!! error TS2354: No best common type exists among return expressions. return new Derived1(); return new Derived2(); }; var f10 = () => { - ~~~~~~~ -!!! error TS2354: No best common type exists among return expressions. return new Derived1(); return new Derived2(); }; function f11() { - ~~~ -!!! error TS2354: No best common type exists among return expressions. return new Base(); return new AnotherClass(); } var f12 = function () { - ~~~~~~~~ -!!! error TS2354: No best common type exists among return expressions. return new Base(); return new AnotherClass(); }; var f13 = () => { - ~~~~~~~ -!!! error TS2354: No best common type exists among return expressions. return new Base(); return new AnotherClass(); }; diff --git a/tests/baselines/reference/functionWithMultipleReturnStatements.errors.txt b/tests/baselines/reference/functionWithMultipleReturnStatements.errors.txt deleted file mode 100644 index cc10d4c782c..00000000000 --- a/tests/baselines/reference/functionWithMultipleReturnStatements.errors.txt +++ /dev/null @@ -1,85 +0,0 @@ -tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(5,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(13,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(23,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(32,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(44,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts(49,10): error TS2354: No best common type exists among return expressions. - - -==== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts (6 errors) ==== - - // return type of a function with multiple returns is the BCT of each return statement - // it is an error if there is no single BCT, these are error cases - - function f1() { - ~~ -!!! error TS2354: No best common type exists among return expressions. - if (true) { - return 1; - } else { - return ''; - } - } - - function f2() { - ~~ -!!! error TS2354: No best common type exists among return expressions. - if (true) { - return 1; - } else if (false) { - return 2; - } else { - return ''; - } - } - - function f3() { - ~~ -!!! error TS2354: No best common type exists among return expressions. - try { - return 1; - } - catch (e) { - return ''; - } - } - - function f4() { - ~~ -!!! error TS2354: No best common type exists among return expressions. - try { - return 1; - } - catch (e) { - - } - finally { - return ''; - } - } - - function f5() { - ~~ -!!! error TS2354: No best common type exists among return expressions. - return 1; - return ''; - } - - function f6(x: T, y:U) { - ~~ -!!! error TS2354: No best common type exists among return expressions. - if (true) { - return x; - } else { - return y; - } - } - - function f8(x: T, y: U) { - if (true) { - return x; - } else { - return y; - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/functionWithMultipleReturnStatements.symbols b/tests/baselines/reference/functionWithMultipleReturnStatements.symbols new file mode 100644 index 00000000000..a33db459640 --- /dev/null +++ b/tests/baselines/reference/functionWithMultipleReturnStatements.symbols @@ -0,0 +1,103 @@ +=== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts === + +// return type of a function with multiple returns is the BCT of each return statement +// it is an error if there is no single BCT, these are error cases + +function f1() { +>f1 : Symbol(f1, Decl(functionWithMultipleReturnStatements.ts, 0, 0)) + + if (true) { + return 1; + } else { + return ''; + } +} + +function f2() { +>f2 : Symbol(f2, Decl(functionWithMultipleReturnStatements.ts, 10, 1)) + + if (true) { + return 1; + } else if (false) { + return 2; + } else { + return ''; + } +} + +function f3() { +>f3 : Symbol(f3, Decl(functionWithMultipleReturnStatements.ts, 20, 1)) + + try { + return 1; + } + catch (e) { +>e : Symbol(e, Decl(functionWithMultipleReturnStatements.ts, 26, 11)) + + return ''; + } +} + +function f4() { +>f4 : Symbol(f4, Decl(functionWithMultipleReturnStatements.ts, 29, 1)) + + try { + return 1; + } + catch (e) { +>e : Symbol(e, Decl(functionWithMultipleReturnStatements.ts, 35, 11)) + + } + finally { + return ''; + } +} + +function f5() { +>f5 : Symbol(f5, Decl(functionWithMultipleReturnStatements.ts, 41, 1)) + + return 1; + return ''; +} + +function f6(x: T, y:U) { +>f6 : Symbol(f6, Decl(functionWithMultipleReturnStatements.ts, 46, 1)) +>T : Symbol(T, Decl(functionWithMultipleReturnStatements.ts, 48, 12)) +>U : Symbol(U, Decl(functionWithMultipleReturnStatements.ts, 48, 14)) +>x : Symbol(x, Decl(functionWithMultipleReturnStatements.ts, 48, 18)) +>T : Symbol(T, Decl(functionWithMultipleReturnStatements.ts, 48, 12)) +>y : Symbol(y, Decl(functionWithMultipleReturnStatements.ts, 48, 23)) +>U : Symbol(U, Decl(functionWithMultipleReturnStatements.ts, 48, 14)) + + if (true) { + return x; +>x : Symbol(x, Decl(functionWithMultipleReturnStatements.ts, 48, 18)) + + } else { + return y; +>y : Symbol(y, Decl(functionWithMultipleReturnStatements.ts, 48, 23)) + } +} + +function f8(x: T, y: U) { +>f8 : Symbol(f8, Decl(functionWithMultipleReturnStatements.ts, 54, 1)) +>T : Symbol(T, Decl(functionWithMultipleReturnStatements.ts, 56, 12)) +>U : Symbol(U, Decl(functionWithMultipleReturnStatements.ts, 56, 24)) +>U : Symbol(U, Decl(functionWithMultipleReturnStatements.ts, 56, 24)) +>V : Symbol(V, Decl(functionWithMultipleReturnStatements.ts, 56, 37)) +>V : Symbol(V, Decl(functionWithMultipleReturnStatements.ts, 56, 37)) +>x : Symbol(x, Decl(functionWithMultipleReturnStatements.ts, 56, 41)) +>T : Symbol(T, Decl(functionWithMultipleReturnStatements.ts, 56, 12)) +>y : Symbol(y, Decl(functionWithMultipleReturnStatements.ts, 56, 46)) +>U : Symbol(U, Decl(functionWithMultipleReturnStatements.ts, 56, 24)) + + if (true) { + return x; +>x : Symbol(x, Decl(functionWithMultipleReturnStatements.ts, 56, 41)) + + } else { + return y; +>y : Symbol(y, Decl(functionWithMultipleReturnStatements.ts, 56, 46)) + } +} + diff --git a/tests/baselines/reference/functionWithMultipleReturnStatements.types b/tests/baselines/reference/functionWithMultipleReturnStatements.types new file mode 100644 index 00000000000..63cbe235c38 --- /dev/null +++ b/tests/baselines/reference/functionWithMultipleReturnStatements.types @@ -0,0 +1,128 @@ +=== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts === + +// return type of a function with multiple returns is the BCT of each return statement +// it is an error if there is no single BCT, these are error cases + +function f1() { +>f1 : () => string | number + + if (true) { +>true : boolean + + return 1; +>1 : number + + } else { + return ''; +>'' : string + } +} + +function f2() { +>f2 : () => string | number + + if (true) { +>true : boolean + + return 1; +>1 : number + + } else if (false) { +>false : boolean + + return 2; +>2 : number + + } else { + return ''; +>'' : string + } +} + +function f3() { +>f3 : () => string | number + + try { + return 1; +>1 : number + } + catch (e) { +>e : any + + return ''; +>'' : string + } +} + +function f4() { +>f4 : () => string | number + + try { + return 1; +>1 : number + } + catch (e) { +>e : any + + } + finally { + return ''; +>'' : string + } +} + +function f5() { +>f5 : () => string | number + + return 1; +>1 : number + + return ''; +>'' : string +} + +function f6(x: T, y:U) { +>f6 : (x: T, y: U) => T | U +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U + + if (true) { +>true : boolean + + return x; +>x : T + + } else { + return y; +>y : U + } +} + +function f8(x: T, y: U) { +>f8 : (x: T, y: U) => U +>T : T +>U : U +>U : U +>V : V +>V : V +>x : T +>T : T +>y : U +>U : U + + if (true) { +>true : boolean + + return x; +>x : T + + } else { + return y; +>y : U + } +} + diff --git a/tests/baselines/reference/functionWithMultipleReturnStatements2.errors.txt b/tests/baselines/reference/functionWithMultipleReturnStatements2.errors.txt deleted file mode 100644 index 0399c7a79a6..00000000000 --- a/tests/baselines/reference/functionWithMultipleReturnStatements2.errors.txt +++ /dev/null @@ -1,101 +0,0 @@ -tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts(59,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts(68,10): error TS2354: No best common type exists among return expressions. - - -==== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts (2 errors) ==== - - // return type of a function with multiple returns is the BCT of each return statement - // no errors expected here - - function f1() { - if (true) { - return 1; - } else { - return null; - } - } - - function f2() { - if (true) { - return 1; - } else if (false) { - return null; - } else { - return 2; - } - } - - function f4() { - try { - return 1; - } - catch (e) { - return undefined; - } - finally { - return 1; - } - } - - function f5() { - return 1; - return new Object(); - } - - function f6(x: T) { - if (true) { - return x; - } else { - return null; - } - } - - //function f7(x: T, y: U) { - // if (true) { - // return x; - // } else { - // return y; - // } - //} - - var a: { x: number; y?: number }; - var b: { x: number; z?: number }; - // returns typeof a - function f9() { - ~~ -!!! error TS2354: No best common type exists among return expressions. - if (true) { - return a; - } else { - return b; - } - } - - // returns typeof b - function f10() { - ~~~ -!!! error TS2354: No best common type exists among return expressions. - if (true) { - return b; - } else { - return a; - } - } - - // returns number => void - function f11() { - if (true) { - return (x: number) => { } - } else { - return (x: Object) => { } - } - } - - // returns Object => void - function f12() { - if (true) { - return (x: Object) => { } - } else { - return (x: number) => { } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/functionWithMultipleReturnStatements2.symbols b/tests/baselines/reference/functionWithMultipleReturnStatements2.symbols new file mode 100644 index 00000000000..39cad6bc414 --- /dev/null +++ b/tests/baselines/reference/functionWithMultipleReturnStatements2.symbols @@ -0,0 +1,142 @@ +=== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts === + +// return type of a function with multiple returns is the BCT of each return statement +// no errors expected here + +function f1() { +>f1 : Symbol(f1, Decl(functionWithMultipleReturnStatements2.ts, 0, 0)) + + if (true) { + return 1; + } else { + return null; + } +} + +function f2() { +>f2 : Symbol(f2, Decl(functionWithMultipleReturnStatements2.ts, 10, 1)) + + if (true) { + return 1; + } else if (false) { + return null; + } else { + return 2; + } +} + +function f4() { +>f4 : Symbol(f4, Decl(functionWithMultipleReturnStatements2.ts, 20, 1)) + + try { + return 1; + } + catch (e) { +>e : Symbol(e, Decl(functionWithMultipleReturnStatements2.ts, 26, 11)) + + return undefined; +>undefined : Symbol(undefined) + } + finally { + return 1; + } +} + +function f5() { +>f5 : Symbol(f5, Decl(functionWithMultipleReturnStatements2.ts, 32, 1)) + + return 1; + return new Object(); +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +function f6(x: T) { +>f6 : Symbol(f6, Decl(functionWithMultipleReturnStatements2.ts, 37, 1)) +>T : Symbol(T, Decl(functionWithMultipleReturnStatements2.ts, 39, 12)) +>x : Symbol(x, Decl(functionWithMultipleReturnStatements2.ts, 39, 15)) +>T : Symbol(T, Decl(functionWithMultipleReturnStatements2.ts, 39, 12)) + + if (true) { + return x; +>x : Symbol(x, Decl(functionWithMultipleReturnStatements2.ts, 39, 15)) + + } else { + return null; + } +} + +//function f7(x: T, y: U) { +// if (true) { +// return x; +// } else { +// return y; +// } +//} + +var a: { x: number; y?: number }; +>a : Symbol(a, Decl(functionWithMultipleReturnStatements2.ts, 55, 3)) +>x : Symbol(x, Decl(functionWithMultipleReturnStatements2.ts, 55, 8)) +>y : Symbol(y, Decl(functionWithMultipleReturnStatements2.ts, 55, 19)) + +var b: { x: number; z?: number }; +>b : Symbol(b, Decl(functionWithMultipleReturnStatements2.ts, 56, 3)) +>x : Symbol(x, Decl(functionWithMultipleReturnStatements2.ts, 56, 8)) +>z : Symbol(z, Decl(functionWithMultipleReturnStatements2.ts, 56, 19)) + +// returns typeof a +function f9() { +>f9 : Symbol(f9, Decl(functionWithMultipleReturnStatements2.ts, 56, 33)) + + if (true) { + return a; +>a : Symbol(a, Decl(functionWithMultipleReturnStatements2.ts, 55, 3)) + + } else { + return b; +>b : Symbol(b, Decl(functionWithMultipleReturnStatements2.ts, 56, 3)) + } +} + +// returns typeof b +function f10() { +>f10 : Symbol(f10, Decl(functionWithMultipleReturnStatements2.ts, 64, 1)) + + if (true) { + return b; +>b : Symbol(b, Decl(functionWithMultipleReturnStatements2.ts, 56, 3)) + + } else { + return a; +>a : Symbol(a, Decl(functionWithMultipleReturnStatements2.ts, 55, 3)) + } +} + +// returns number => void +function f11() { +>f11 : Symbol(f11, Decl(functionWithMultipleReturnStatements2.ts, 73, 1)) + + if (true) { + return (x: number) => { } +>x : Symbol(x, Decl(functionWithMultipleReturnStatements2.ts, 78, 16)) + + } else { + return (x: Object) => { } +>x : Symbol(x, Decl(functionWithMultipleReturnStatements2.ts, 80, 16)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + } +} + +// returns Object => void +function f12() { +>f12 : Symbol(f12, Decl(functionWithMultipleReturnStatements2.ts, 82, 1)) + + if (true) { + return (x: Object) => { } +>x : Symbol(x, Decl(functionWithMultipleReturnStatements2.ts, 87, 16)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + + } else { + return (x: number) => { } +>x : Symbol(x, Decl(functionWithMultipleReturnStatements2.ts, 89, 16)) + } +} diff --git a/tests/baselines/reference/functionWithMultipleReturnStatements2.types b/tests/baselines/reference/functionWithMultipleReturnStatements2.types new file mode 100644 index 00000000000..7700329971a --- /dev/null +++ b/tests/baselines/reference/functionWithMultipleReturnStatements2.types @@ -0,0 +1,176 @@ +=== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts === + +// return type of a function with multiple returns is the BCT of each return statement +// no errors expected here + +function f1() { +>f1 : () => number + + if (true) { +>true : boolean + + return 1; +>1 : number + + } else { + return null; +>null : null + } +} + +function f2() { +>f2 : () => number + + if (true) { +>true : boolean + + return 1; +>1 : number + + } else if (false) { +>false : boolean + + return null; +>null : null + + } else { + return 2; +>2 : number + } +} + +function f4() { +>f4 : () => number + + try { + return 1; +>1 : number + } + catch (e) { +>e : any + + return undefined; +>undefined : undefined + } + finally { + return 1; +>1 : number + } +} + +function f5() { +>f5 : () => Object + + return 1; +>1 : number + + return new Object(); +>new Object() : Object +>Object : ObjectConstructor +} + +function f6(x: T) { +>f6 : (x: T) => T +>T : T +>x : T +>T : T + + if (true) { +>true : boolean + + return x; +>x : T + + } else { + return null; +>null : null + } +} + +//function f7(x: T, y: U) { +// if (true) { +// return x; +// } else { +// return y; +// } +//} + +var a: { x: number; y?: number }; +>a : { x: number; y?: number; } +>x : number +>y : number + +var b: { x: number; z?: number }; +>b : { x: number; z?: number; } +>x : number +>z : number + +// returns typeof a +function f9() { +>f9 : () => { x: number; y?: number; } | { x: number; z?: number; } + + if (true) { +>true : boolean + + return a; +>a : { x: number; y?: number; } + + } else { + return b; +>b : { x: number; z?: number; } + } +} + +// returns typeof b +function f10() { +>f10 : () => { x: number; y?: number; } | { x: number; z?: number; } + + if (true) { +>true : boolean + + return b; +>b : { x: number; z?: number; } + + } else { + return a; +>a : { x: number; y?: number; } + } +} + +// returns number => void +function f11() { +>f11 : () => (x: number) => void + + if (true) { +>true : boolean + + return (x: number) => { } +>(x: number) => { } : (x: number) => void +>x : number + + } else { + return (x: Object) => { } +>(x: Object) => { } : (x: Object) => void +>x : Object +>Object : Object + } +} + +// returns Object => void +function f12() { +>f12 : () => (x: Object) => void + + if (true) { +>true : boolean + + return (x: Object) => { } +>(x: Object) => { } : (x: Object) => void +>x : Object +>Object : Object + + } else { + return (x: number) => { } +>(x: number) => { } : (x: number) => void +>x : number + } +} diff --git a/tests/baselines/reference/functionWithNoBestCommonType1.errors.txt b/tests/baselines/reference/functionWithNoBestCommonType1.errors.txt deleted file mode 100644 index 86234b7dd81..00000000000 --- a/tests/baselines/reference/functionWithNoBestCommonType1.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/compiler/functionWithNoBestCommonType1.ts(2,10): error TS2354: No best common type exists among return expressions. - - -==== tests/cases/compiler/functionWithNoBestCommonType1.ts (1 errors) ==== - - function foo() { - ~~~ -!!! error TS2354: No best common type exists among return expressions. - return true; - return bar(); - } - - function bar(): void { - } \ No newline at end of file diff --git a/tests/baselines/reference/functionWithNoBestCommonType1.symbols b/tests/baselines/reference/functionWithNoBestCommonType1.symbols new file mode 100644 index 00000000000..826b23f1b48 --- /dev/null +++ b/tests/baselines/reference/functionWithNoBestCommonType1.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/functionWithNoBestCommonType1.ts === + +function foo() { +>foo : Symbol(foo, Decl(functionWithNoBestCommonType1.ts, 0, 0)) + + return true; + return bar(); +>bar : Symbol(bar, Decl(functionWithNoBestCommonType1.ts, 4, 1)) +} + +function bar(): void { +>bar : Symbol(bar, Decl(functionWithNoBestCommonType1.ts, 4, 1)) +} diff --git a/tests/baselines/reference/functionWithNoBestCommonType1.types b/tests/baselines/reference/functionWithNoBestCommonType1.types new file mode 100644 index 00000000000..801c25d239f --- /dev/null +++ b/tests/baselines/reference/functionWithNoBestCommonType1.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/functionWithNoBestCommonType1.ts === + +function foo() { +>foo : () => boolean | void + + return true; +>true : boolean + + return bar(); +>bar() : void +>bar : () => void +} + +function bar(): void { +>bar : () => void +} diff --git a/tests/baselines/reference/functionWithNoBestCommonType2.errors.txt b/tests/baselines/reference/functionWithNoBestCommonType2.errors.txt deleted file mode 100644 index 6ce898e447c..00000000000 --- a/tests/baselines/reference/functionWithNoBestCommonType2.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/compiler/functionWithNoBestCommonType2.ts(2,9): error TS2354: No best common type exists among return expressions. - - -==== tests/cases/compiler/functionWithNoBestCommonType2.ts (1 errors) ==== - - var v = function () { - ~~~~~~~~ -!!! error TS2354: No best common type exists among return expressions. - return true; - return bar(); - }; - - function bar(): void { - } \ No newline at end of file diff --git a/tests/baselines/reference/functionWithNoBestCommonType2.symbols b/tests/baselines/reference/functionWithNoBestCommonType2.symbols new file mode 100644 index 00000000000..f32f86e67a9 --- /dev/null +++ b/tests/baselines/reference/functionWithNoBestCommonType2.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/functionWithNoBestCommonType2.ts === + +var v = function () { +>v : Symbol(v, Decl(functionWithNoBestCommonType2.ts, 1, 3)) + + return true; + return bar(); +>bar : Symbol(bar, Decl(functionWithNoBestCommonType2.ts, 4, 2)) + +}; + +function bar(): void { +>bar : Symbol(bar, Decl(functionWithNoBestCommonType2.ts, 4, 2)) +} diff --git a/tests/baselines/reference/functionWithNoBestCommonType2.types b/tests/baselines/reference/functionWithNoBestCommonType2.types new file mode 100644 index 00000000000..cae5f1dbb64 --- /dev/null +++ b/tests/baselines/reference/functionWithNoBestCommonType2.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/functionWithNoBestCommonType2.ts === + +var v = function () { +>v : () => boolean | void +>function () { return true; return bar();} : () => boolean | void + + return true; +>true : boolean + + return bar(); +>bar() : void +>bar : () => void + +}; + +function bar(): void { +>bar : () => void +} diff --git a/tests/baselines/reference/generatorTypeCheck22.errors.txt b/tests/baselines/reference/generatorTypeCheck22.errors.txt deleted file mode 100644 index ab2b3de4f42..00000000000 --- a/tests/baselines/reference/generatorTypeCheck22.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck22.ts(4,11): error TS2504: No best common type exists among yield expressions. - - -==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck22.ts (1 errors) ==== - class Foo { x: number } - class Bar extends Foo { y: string } - class Baz { z: number } - function* g3() { - ~~ -!!! error TS2504: No best common type exists among yield expressions. - yield; - yield new Bar; - yield new Baz; - yield *[new Bar]; - yield *[new Baz]; - } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck22.symbols b/tests/baselines/reference/generatorTypeCheck22.symbols new file mode 100644 index 00000000000..ae3bdac88f3 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck22.symbols @@ -0,0 +1,30 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck22.ts === +class Foo { x: number } +>Foo : Symbol(Foo, Decl(generatorTypeCheck22.ts, 0, 0)) +>x : Symbol(Foo.x, Decl(generatorTypeCheck22.ts, 0, 11)) + +class Bar extends Foo { y: string } +>Bar : Symbol(Bar, Decl(generatorTypeCheck22.ts, 0, 23)) +>Foo : Symbol(Foo, Decl(generatorTypeCheck22.ts, 0, 0)) +>y : Symbol(Bar.y, Decl(generatorTypeCheck22.ts, 1, 23)) + +class Baz { z: number } +>Baz : Symbol(Baz, Decl(generatorTypeCheck22.ts, 1, 35)) +>z : Symbol(Baz.z, Decl(generatorTypeCheck22.ts, 2, 11)) + +function* g3() { +>g3 : Symbol(g3, Decl(generatorTypeCheck22.ts, 2, 23)) + + yield; + yield new Bar; +>Bar : Symbol(Bar, Decl(generatorTypeCheck22.ts, 0, 23)) + + yield new Baz; +>Baz : Symbol(Baz, Decl(generatorTypeCheck22.ts, 1, 35)) + + yield *[new Bar]; +>Bar : Symbol(Bar, Decl(generatorTypeCheck22.ts, 0, 23)) + + yield *[new Baz]; +>Baz : Symbol(Baz, Decl(generatorTypeCheck22.ts, 1, 35)) +} diff --git a/tests/baselines/reference/generatorTypeCheck22.types b/tests/baselines/reference/generatorTypeCheck22.types new file mode 100644 index 00000000000..e46e73874e6 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck22.types @@ -0,0 +1,42 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck22.ts === +class Foo { x: number } +>Foo : Foo +>x : number + +class Bar extends Foo { y: string } +>Bar : Bar +>Foo : Foo +>y : string + +class Baz { z: number } +>Baz : Baz +>z : number + +function* g3() { +>g3 : () => IterableIterator + + yield; +>yield : any + + yield new Bar; +>yield new Bar : any +>new Bar : Bar +>Bar : typeof Bar + + yield new Baz; +>yield new Baz : any +>new Baz : Baz +>Baz : typeof Baz + + yield *[new Bar]; +>yield *[new Bar] : any +>[new Bar] : Bar[] +>new Bar : Bar +>Bar : typeof Bar + + yield *[new Baz]; +>yield *[new Baz] : any +>[new Baz] : Baz[] +>new Baz : Baz +>Baz : typeof Baz +} diff --git a/tests/baselines/reference/generatorTypeCheck23.errors.txt b/tests/baselines/reference/generatorTypeCheck23.errors.txt deleted file mode 100644 index 9e85117a0a8..00000000000 --- a/tests/baselines/reference/generatorTypeCheck23.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck23.ts(4,11): error TS2504: No best common type exists among yield expressions. - - -==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck23.ts (1 errors) ==== - class Foo { x: number } - class Bar extends Foo { y: string } - class Baz { z: number } - function* g3() { - ~~ -!!! error TS2504: No best common type exists among yield expressions. - yield; - yield new Foo; - yield new Bar; - yield new Baz; - yield *[new Bar]; - yield *[new Baz]; - } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck23.symbols b/tests/baselines/reference/generatorTypeCheck23.symbols new file mode 100644 index 00000000000..507906f500b --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck23.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck23.ts === +class Foo { x: number } +>Foo : Symbol(Foo, Decl(generatorTypeCheck23.ts, 0, 0)) +>x : Symbol(Foo.x, Decl(generatorTypeCheck23.ts, 0, 11)) + +class Bar extends Foo { y: string } +>Bar : Symbol(Bar, Decl(generatorTypeCheck23.ts, 0, 23)) +>Foo : Symbol(Foo, Decl(generatorTypeCheck23.ts, 0, 0)) +>y : Symbol(Bar.y, Decl(generatorTypeCheck23.ts, 1, 23)) + +class Baz { z: number } +>Baz : Symbol(Baz, Decl(generatorTypeCheck23.ts, 1, 35)) +>z : Symbol(Baz.z, Decl(generatorTypeCheck23.ts, 2, 11)) + +function* g3() { +>g3 : Symbol(g3, Decl(generatorTypeCheck23.ts, 2, 23)) + + yield; + yield new Foo; +>Foo : Symbol(Foo, Decl(generatorTypeCheck23.ts, 0, 0)) + + yield new Bar; +>Bar : Symbol(Bar, Decl(generatorTypeCheck23.ts, 0, 23)) + + yield new Baz; +>Baz : Symbol(Baz, Decl(generatorTypeCheck23.ts, 1, 35)) + + yield *[new Bar]; +>Bar : Symbol(Bar, Decl(generatorTypeCheck23.ts, 0, 23)) + + yield *[new Baz]; +>Baz : Symbol(Baz, Decl(generatorTypeCheck23.ts, 1, 35)) +} diff --git a/tests/baselines/reference/generatorTypeCheck23.types b/tests/baselines/reference/generatorTypeCheck23.types new file mode 100644 index 00000000000..1d5d294503a --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck23.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck23.ts === +class Foo { x: number } +>Foo : Foo +>x : number + +class Bar extends Foo { y: string } +>Bar : Bar +>Foo : Foo +>y : string + +class Baz { z: number } +>Baz : Baz +>z : number + +function* g3() { +>g3 : () => IterableIterator + + yield; +>yield : any + + yield new Foo; +>yield new Foo : any +>new Foo : Foo +>Foo : typeof Foo + + yield new Bar; +>yield new Bar : any +>new Bar : Bar +>Bar : typeof Bar + + yield new Baz; +>yield new Baz : any +>new Baz : Baz +>Baz : typeof Baz + + yield *[new Bar]; +>yield *[new Bar] : any +>[new Bar] : Bar[] +>new Bar : Bar +>Bar : typeof Bar + + yield *[new Baz]; +>yield *[new Baz] : any +>[new Baz] : Baz[] +>new Baz : Baz +>Baz : typeof Baz +} diff --git a/tests/baselines/reference/generatorTypeCheck24.errors.txt b/tests/baselines/reference/generatorTypeCheck24.errors.txt deleted file mode 100644 index b4ca13c14c2..00000000000 --- a/tests/baselines/reference/generatorTypeCheck24.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck24.ts(4,11): error TS2504: No best common type exists among yield expressions. - - -==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck24.ts (1 errors) ==== - class Foo { x: number } - class Bar extends Foo { y: string } - class Baz { z: number } - function* g3() { - ~~ -!!! error TS2504: No best common type exists among yield expressions. - yield; - yield * [new Foo]; - yield new Bar; - yield new Baz; - yield *[new Bar]; - yield *[new Baz]; - } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck24.symbols b/tests/baselines/reference/generatorTypeCheck24.symbols new file mode 100644 index 00000000000..b0bc5307b89 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck24.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck24.ts === +class Foo { x: number } +>Foo : Symbol(Foo, Decl(generatorTypeCheck24.ts, 0, 0)) +>x : Symbol(Foo.x, Decl(generatorTypeCheck24.ts, 0, 11)) + +class Bar extends Foo { y: string } +>Bar : Symbol(Bar, Decl(generatorTypeCheck24.ts, 0, 23)) +>Foo : Symbol(Foo, Decl(generatorTypeCheck24.ts, 0, 0)) +>y : Symbol(Bar.y, Decl(generatorTypeCheck24.ts, 1, 23)) + +class Baz { z: number } +>Baz : Symbol(Baz, Decl(generatorTypeCheck24.ts, 1, 35)) +>z : Symbol(Baz.z, Decl(generatorTypeCheck24.ts, 2, 11)) + +function* g3() { +>g3 : Symbol(g3, Decl(generatorTypeCheck24.ts, 2, 23)) + + yield; + yield * [new Foo]; +>Foo : Symbol(Foo, Decl(generatorTypeCheck24.ts, 0, 0)) + + yield new Bar; +>Bar : Symbol(Bar, Decl(generatorTypeCheck24.ts, 0, 23)) + + yield new Baz; +>Baz : Symbol(Baz, Decl(generatorTypeCheck24.ts, 1, 35)) + + yield *[new Bar]; +>Bar : Symbol(Bar, Decl(generatorTypeCheck24.ts, 0, 23)) + + yield *[new Baz]; +>Baz : Symbol(Baz, Decl(generatorTypeCheck24.ts, 1, 35)) +} diff --git a/tests/baselines/reference/generatorTypeCheck24.types b/tests/baselines/reference/generatorTypeCheck24.types new file mode 100644 index 00000000000..e3c369bfce1 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck24.types @@ -0,0 +1,48 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck24.ts === +class Foo { x: number } +>Foo : Foo +>x : number + +class Bar extends Foo { y: string } +>Bar : Bar +>Foo : Foo +>y : string + +class Baz { z: number } +>Baz : Baz +>z : number + +function* g3() { +>g3 : () => IterableIterator + + yield; +>yield : any + + yield * [new Foo]; +>yield * [new Foo] : any +>[new Foo] : Foo[] +>new Foo : Foo +>Foo : typeof Foo + + yield new Bar; +>yield new Bar : any +>new Bar : Bar +>Bar : typeof Bar + + yield new Baz; +>yield new Baz : any +>new Baz : Baz +>Baz : typeof Baz + + yield *[new Bar]; +>yield *[new Bar] : any +>[new Bar] : Bar[] +>new Bar : Bar +>Bar : typeof Bar + + yield *[new Baz]; +>yield *[new Baz] : any +>[new Baz] : Baz[] +>new Baz : Baz +>Baz : typeof Baz +} diff --git a/tests/baselines/reference/generatorTypeCheck52.errors.txt b/tests/baselines/reference/generatorTypeCheck52.errors.txt deleted file mode 100644 index 8dc280bb8c9..00000000000 --- a/tests/baselines/reference/generatorTypeCheck52.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck52.ts(3,11): error TS2504: No best common type exists among yield expressions. - - -==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck52.ts (1 errors) ==== - class Foo { x: number } - class Baz { z: number } - function* g() { - ~ -!!! error TS2504: No best common type exists among yield expressions. - yield new Foo; - yield new Baz; - } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck52.symbols b/tests/baselines/reference/generatorTypeCheck52.symbols new file mode 100644 index 00000000000..64c29f98438 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck52.symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck52.ts === +class Foo { x: number } +>Foo : Symbol(Foo, Decl(generatorTypeCheck52.ts, 0, 0)) +>x : Symbol(Foo.x, Decl(generatorTypeCheck52.ts, 0, 11)) + +class Baz { z: number } +>Baz : Symbol(Baz, Decl(generatorTypeCheck52.ts, 0, 23)) +>z : Symbol(Baz.z, Decl(generatorTypeCheck52.ts, 1, 11)) + +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck52.ts, 1, 23)) + + yield new Foo; +>Foo : Symbol(Foo, Decl(generatorTypeCheck52.ts, 0, 0)) + + yield new Baz; +>Baz : Symbol(Baz, Decl(generatorTypeCheck52.ts, 0, 23)) +} diff --git a/tests/baselines/reference/generatorTypeCheck52.types b/tests/baselines/reference/generatorTypeCheck52.types new file mode 100644 index 00000000000..97ac442aa0e --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck52.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck52.ts === +class Foo { x: number } +>Foo : Foo +>x : number + +class Baz { z: number } +>Baz : Baz +>z : number + +function* g() { +>g : () => IterableIterator + + yield new Foo; +>yield new Foo : any +>new Foo : Foo +>Foo : typeof Foo + + yield new Baz; +>yield new Baz : any +>new Baz : Baz +>Baz : typeof Baz +} diff --git a/tests/baselines/reference/generatorTypeCheck53.errors.txt b/tests/baselines/reference/generatorTypeCheck53.errors.txt deleted file mode 100644 index ee3512f34c5..00000000000 --- a/tests/baselines/reference/generatorTypeCheck53.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck53.ts(3,11): error TS2504: No best common type exists among yield expressions. - - -==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck53.ts (1 errors) ==== - class Foo { x: number } - class Baz { z: number } - function* g() { - ~ -!!! error TS2504: No best common type exists among yield expressions. - yield new Foo; - yield* [new Baz]; - } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck53.symbols b/tests/baselines/reference/generatorTypeCheck53.symbols new file mode 100644 index 00000000000..ce573dbf422 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck53.symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck53.ts === +class Foo { x: number } +>Foo : Symbol(Foo, Decl(generatorTypeCheck53.ts, 0, 0)) +>x : Symbol(Foo.x, Decl(generatorTypeCheck53.ts, 0, 11)) + +class Baz { z: number } +>Baz : Symbol(Baz, Decl(generatorTypeCheck53.ts, 0, 23)) +>z : Symbol(Baz.z, Decl(generatorTypeCheck53.ts, 1, 11)) + +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck53.ts, 1, 23)) + + yield new Foo; +>Foo : Symbol(Foo, Decl(generatorTypeCheck53.ts, 0, 0)) + + yield* [new Baz]; +>Baz : Symbol(Baz, Decl(generatorTypeCheck53.ts, 0, 23)) +} diff --git a/tests/baselines/reference/generatorTypeCheck53.types b/tests/baselines/reference/generatorTypeCheck53.types new file mode 100644 index 00000000000..b91974e9807 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck53.types @@ -0,0 +1,23 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck53.ts === +class Foo { x: number } +>Foo : Foo +>x : number + +class Baz { z: number } +>Baz : Baz +>z : number + +function* g() { +>g : () => IterableIterator + + yield new Foo; +>yield new Foo : any +>new Foo : Foo +>Foo : typeof Foo + + yield* [new Baz]; +>yield* [new Baz] : any +>[new Baz] : Baz[] +>new Baz : Baz +>Baz : typeof Baz +} diff --git a/tests/baselines/reference/generatorTypeCheck54.errors.txt b/tests/baselines/reference/generatorTypeCheck54.errors.txt deleted file mode 100644 index de22dbfc6e8..00000000000 --- a/tests/baselines/reference/generatorTypeCheck54.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck54.ts(3,11): error TS2504: No best common type exists among yield expressions. - - -==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck54.ts (1 errors) ==== - class Foo { x: number } - class Baz { z: number } - function* g() { - ~ -!!! error TS2504: No best common type exists among yield expressions. - yield* [new Foo]; - yield* [new Baz]; - } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck54.symbols b/tests/baselines/reference/generatorTypeCheck54.symbols new file mode 100644 index 00000000000..f6230b634f1 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck54.symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck54.ts === +class Foo { x: number } +>Foo : Symbol(Foo, Decl(generatorTypeCheck54.ts, 0, 0)) +>x : Symbol(Foo.x, Decl(generatorTypeCheck54.ts, 0, 11)) + +class Baz { z: number } +>Baz : Symbol(Baz, Decl(generatorTypeCheck54.ts, 0, 23)) +>z : Symbol(Baz.z, Decl(generatorTypeCheck54.ts, 1, 11)) + +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck54.ts, 1, 23)) + + yield* [new Foo]; +>Foo : Symbol(Foo, Decl(generatorTypeCheck54.ts, 0, 0)) + + yield* [new Baz]; +>Baz : Symbol(Baz, Decl(generatorTypeCheck54.ts, 0, 23)) +} diff --git a/tests/baselines/reference/generatorTypeCheck54.types b/tests/baselines/reference/generatorTypeCheck54.types new file mode 100644 index 00000000000..1cdbde67498 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck54.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck54.ts === +class Foo { x: number } +>Foo : Foo +>x : number + +class Baz { z: number } +>Baz : Baz +>z : number + +function* g() { +>g : () => IterableIterator + + yield* [new Foo]; +>yield* [new Foo] : any +>[new Foo] : Foo[] +>new Foo : Foo +>Foo : typeof Foo + + yield* [new Baz]; +>yield* [new Baz] : any +>[new Baz] : Baz[] +>new Baz : Baz +>Baz : typeof Baz +} diff --git a/tests/baselines/reference/inferredFunctionReturnTypeIsEmptyType.errors.txt b/tests/baselines/reference/inferredFunctionReturnTypeIsEmptyType.errors.txt deleted file mode 100644 index bab58d0e4cf..00000000000 --- a/tests/baselines/reference/inferredFunctionReturnTypeIsEmptyType.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/compiler/inferredFunctionReturnTypeIsEmptyType.ts(2,10): error TS2354: No best common type exists among return expressions. - - -==== tests/cases/compiler/inferredFunctionReturnTypeIsEmptyType.ts (1 errors) ==== - - function foo() { - ~~~ -!!! error TS2354: No best common type exists among return expressions. - if (true) { - return 42; - } - else { - return "42"; - } - }; - \ No newline at end of file diff --git a/tests/baselines/reference/inferredFunctionReturnTypeIsEmptyType.symbols b/tests/baselines/reference/inferredFunctionReturnTypeIsEmptyType.symbols new file mode 100644 index 00000000000..059a992c3f3 --- /dev/null +++ b/tests/baselines/reference/inferredFunctionReturnTypeIsEmptyType.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/inferredFunctionReturnTypeIsEmptyType.ts === + +function foo() { +>foo : Symbol(foo, Decl(inferredFunctionReturnTypeIsEmptyType.ts, 0, 0)) + + if (true) { + return 42; + } + else { + return "42"; + } +}; + diff --git a/tests/baselines/reference/inferredFunctionReturnTypeIsEmptyType.types b/tests/baselines/reference/inferredFunctionReturnTypeIsEmptyType.types new file mode 100644 index 00000000000..9c1d4aa31b0 --- /dev/null +++ b/tests/baselines/reference/inferredFunctionReturnTypeIsEmptyType.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/inferredFunctionReturnTypeIsEmptyType.ts === + +function foo() { +>foo : () => string | number + + if (true) { +>true : boolean + + return 42; +>42 : number + } + else { + return "42"; +>"42" : string + } +}; + diff --git a/tests/baselines/reference/stringLiteralTypesOverloads02.errors.txt b/tests/baselines/reference/stringLiteralTypesOverloads02.errors.txt deleted file mode 100644 index 995cf687b70..00000000000 --- a/tests/baselines/reference/stringLiteralTypesOverloads02.errors.txt +++ /dev/null @@ -1,57 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(9,10): error TS2354: No best common type exists among return expressions. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts (1 errors) ==== - - function getFalsyPrimitive(x: "string"): string; - function getFalsyPrimitive(x: "number"): number; - function getFalsyPrimitive(x: "boolean"): boolean; - function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; - function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; - function getFalsyPrimitive(x: "number" | "string"): number | string; - function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; - function getFalsyPrimitive(x: string) { - ~~~~~~~~~~~~~~~~~ -!!! error TS2354: No best common type exists among return expressions. - if (x === "string") { - return ""; - } - if (x === "number") { - return 0; - } - if (x === "boolean") { - return false; - } - - // Should be unreachable. - throw "Invalid value"; - } - - namespace Consts1 { - const EMPTY_STRING = getFalsyPrimitive("string"); - const ZERO = getFalsyPrimitive('number'); - const FALSE = getFalsyPrimitive("boolean"); - } - - const string: "string" = "string" - const number: "number" = "number" - const boolean: "boolean" = "boolean" - - const stringOrNumber = string || number; - const stringOrBoolean = string || boolean; - const booleanOrNumber = number || boolean; - const stringOrBooleanOrNumber = stringOrBoolean || number; - - namespace Consts2 { - const EMPTY_STRING = getFalsyPrimitive(string); - const ZERO = getFalsyPrimitive(number); - const FALSE = getFalsyPrimitive(boolean); - - const a = getFalsyPrimitive(stringOrNumber); - const b = getFalsyPrimitive(stringOrBoolean); - const c = getFalsyPrimitive(booleanOrNumber); - const d = getFalsyPrimitive(stringOrBooleanOrNumber); - } - - - \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesOverloads02.symbols b/tests/baselines/reference/stringLiteralTypesOverloads02.symbols new file mode 100644 index 00000000000..7c95a42b10f --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloads02.symbols @@ -0,0 +1,140 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts === + +function getFalsyPrimitive(x: "string"): string; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads02.ts, 1, 27)) + +function getFalsyPrimitive(x: "number"): number; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads02.ts, 2, 27)) + +function getFalsyPrimitive(x: "boolean"): boolean; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads02.ts, 3, 27)) + +function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads02.ts, 4, 27)) + +function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads02.ts, 5, 27)) + +function getFalsyPrimitive(x: "number" | "string"): number | string; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads02.ts, 6, 27)) + +function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads02.ts, 7, 27)) + +function getFalsyPrimitive(x: string) { +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads02.ts, 8, 27)) + + if (x === "string") { +>x : Symbol(x, Decl(stringLiteralTypesOverloads02.ts, 8, 27)) + + return ""; + } + if (x === "number") { +>x : Symbol(x, Decl(stringLiteralTypesOverloads02.ts, 8, 27)) + + return 0; + } + if (x === "boolean") { +>x : Symbol(x, Decl(stringLiteralTypesOverloads02.ts, 8, 27)) + + return false; + } + + // Should be unreachable. + throw "Invalid value"; +} + +namespace Consts1 { +>Consts1 : Symbol(Consts1, Decl(stringLiteralTypesOverloads02.ts, 21, 1)) + + const EMPTY_STRING = getFalsyPrimitive("string"); +>EMPTY_STRING : Symbol(EMPTY_STRING, Decl(stringLiteralTypesOverloads02.ts, 24, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) + + const ZERO = getFalsyPrimitive('number'); +>ZERO : Symbol(ZERO, Decl(stringLiteralTypesOverloads02.ts, 25, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) + + const FALSE = getFalsyPrimitive("boolean"); +>FALSE : Symbol(FALSE, Decl(stringLiteralTypesOverloads02.ts, 26, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +} + +const string: "string" = "string" +>string : Symbol(string, Decl(stringLiteralTypesOverloads02.ts, 29, 5)) + +const number: "number" = "number" +>number : Symbol(number, Decl(stringLiteralTypesOverloads02.ts, 30, 5)) + +const boolean: "boolean" = "boolean" +>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads02.ts, 31, 5)) + +const stringOrNumber = string || number; +>stringOrNumber : Symbol(stringOrNumber, Decl(stringLiteralTypesOverloads02.ts, 33, 5)) +>string : Symbol(string, Decl(stringLiteralTypesOverloads02.ts, 29, 5)) +>number : Symbol(number, Decl(stringLiteralTypesOverloads02.ts, 30, 5)) + +const stringOrBoolean = string || boolean; +>stringOrBoolean : Symbol(stringOrBoolean, Decl(stringLiteralTypesOverloads02.ts, 34, 5)) +>string : Symbol(string, Decl(stringLiteralTypesOverloads02.ts, 29, 5)) +>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads02.ts, 31, 5)) + +const booleanOrNumber = number || boolean; +>booleanOrNumber : Symbol(booleanOrNumber, Decl(stringLiteralTypesOverloads02.ts, 35, 5)) +>number : Symbol(number, Decl(stringLiteralTypesOverloads02.ts, 30, 5)) +>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads02.ts, 31, 5)) + +const stringOrBooleanOrNumber = stringOrBoolean || number; +>stringOrBooleanOrNumber : Symbol(stringOrBooleanOrNumber, Decl(stringLiteralTypesOverloads02.ts, 36, 5)) +>stringOrBoolean : Symbol(stringOrBoolean, Decl(stringLiteralTypesOverloads02.ts, 34, 5)) +>number : Symbol(number, Decl(stringLiteralTypesOverloads02.ts, 30, 5)) + +namespace Consts2 { +>Consts2 : Symbol(Consts2, Decl(stringLiteralTypesOverloads02.ts, 36, 58)) + + const EMPTY_STRING = getFalsyPrimitive(string); +>EMPTY_STRING : Symbol(EMPTY_STRING, Decl(stringLiteralTypesOverloads02.ts, 39, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>string : Symbol(string, Decl(stringLiteralTypesOverloads02.ts, 29, 5)) + + const ZERO = getFalsyPrimitive(number); +>ZERO : Symbol(ZERO, Decl(stringLiteralTypesOverloads02.ts, 40, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>number : Symbol(number, Decl(stringLiteralTypesOverloads02.ts, 30, 5)) + + const FALSE = getFalsyPrimitive(boolean); +>FALSE : Symbol(FALSE, Decl(stringLiteralTypesOverloads02.ts, 41, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads02.ts, 31, 5)) + + const a = getFalsyPrimitive(stringOrNumber); +>a : Symbol(a, Decl(stringLiteralTypesOverloads02.ts, 43, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>stringOrNumber : Symbol(stringOrNumber, Decl(stringLiteralTypesOverloads02.ts, 33, 5)) + + const b = getFalsyPrimitive(stringOrBoolean); +>b : Symbol(b, Decl(stringLiteralTypesOverloads02.ts, 44, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>stringOrBoolean : Symbol(stringOrBoolean, Decl(stringLiteralTypesOverloads02.ts, 34, 5)) + + const c = getFalsyPrimitive(booleanOrNumber); +>c : Symbol(c, Decl(stringLiteralTypesOverloads02.ts, 45, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>booleanOrNumber : Symbol(booleanOrNumber, Decl(stringLiteralTypesOverloads02.ts, 35, 5)) + + const d = getFalsyPrimitive(stringOrBooleanOrNumber); +>d : Symbol(d, Decl(stringLiteralTypesOverloads02.ts, 46, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads02.ts, 0, 0), Decl(stringLiteralTypesOverloads02.ts, 1, 48), Decl(stringLiteralTypesOverloads02.ts, 2, 48), Decl(stringLiteralTypesOverloads02.ts, 3, 50), Decl(stringLiteralTypesOverloads02.ts, 4, 70), Decl(stringLiteralTypesOverloads02.ts, 5, 70), Decl(stringLiteralTypesOverloads02.ts, 6, 68), Decl(stringLiteralTypesOverloads02.ts, 7, 90)) +>stringOrBooleanOrNumber : Symbol(stringOrBooleanOrNumber, Decl(stringLiteralTypesOverloads02.ts, 36, 5)) +} + + + diff --git a/tests/baselines/reference/stringLiteralTypesOverloads02.types b/tests/baselines/reference/stringLiteralTypesOverloads02.types new file mode 100644 index 00000000000..91eaea1dca3 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloads02.types @@ -0,0 +1,170 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts === + +function getFalsyPrimitive(x: "string"): string; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : "string" + +function getFalsyPrimitive(x: "number"): number; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : "number" + +function getFalsyPrimitive(x: "boolean"): boolean; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : "boolean" + +function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : "string" | "boolean" + +function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : "number" | "boolean" + +function getFalsyPrimitive(x: "number" | "string"): number | string; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : "string" | "number" + +function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : "string" | "number" | "boolean" + +function getFalsyPrimitive(x: string) { +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : string + + if (x === "string") { +>x === "string" : boolean +>x : string +>"string" : "string" + + return ""; +>"" : string + } + if (x === "number") { +>x === "number" : boolean +>x : string +>"number" : "number" + + return 0; +>0 : number + } + if (x === "boolean") { +>x === "boolean" : boolean +>x : string +>"boolean" : "boolean" + + return false; +>false : boolean + } + + // Should be unreachable. + throw "Invalid value"; +>"Invalid value" : string +} + +namespace Consts1 { +>Consts1 : typeof Consts1 + + const EMPTY_STRING = getFalsyPrimitive("string"); +>EMPTY_STRING : string +>getFalsyPrimitive("string") : string +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>"string" : "string" + + const ZERO = getFalsyPrimitive('number'); +>ZERO : number +>getFalsyPrimitive('number') : number +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>'number' : "number" + + const FALSE = getFalsyPrimitive("boolean"); +>FALSE : boolean +>getFalsyPrimitive("boolean") : boolean +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>"boolean" : "boolean" +} + +const string: "string" = "string" +>string : "string" +>"string" : "string" + +const number: "number" = "number" +>number : "number" +>"number" : "number" + +const boolean: "boolean" = "boolean" +>boolean : "boolean" +>"boolean" : "boolean" + +const stringOrNumber = string || number; +>stringOrNumber : "string" | "number" +>string || number : "string" | "number" +>string : "string" +>number : "number" + +const stringOrBoolean = string || boolean; +>stringOrBoolean : "string" | "boolean" +>string || boolean : "string" | "boolean" +>string : "string" +>boolean : "boolean" + +const booleanOrNumber = number || boolean; +>booleanOrNumber : "number" | "boolean" +>number || boolean : "number" | "boolean" +>number : "number" +>boolean : "boolean" + +const stringOrBooleanOrNumber = stringOrBoolean || number; +>stringOrBooleanOrNumber : "string" | "number" | "boolean" +>stringOrBoolean || number : "string" | "number" | "boolean" +>stringOrBoolean : "string" | "boolean" +>number : "number" + +namespace Consts2 { +>Consts2 : typeof Consts2 + + const EMPTY_STRING = getFalsyPrimitive(string); +>EMPTY_STRING : string +>getFalsyPrimitive(string) : string +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>string : "string" + + const ZERO = getFalsyPrimitive(number); +>ZERO : number +>getFalsyPrimitive(number) : number +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>number : "number" + + const FALSE = getFalsyPrimitive(boolean); +>FALSE : boolean +>getFalsyPrimitive(boolean) : boolean +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>boolean : "boolean" + + const a = getFalsyPrimitive(stringOrNumber); +>a : string | number +>getFalsyPrimitive(stringOrNumber) : string | number +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>stringOrNumber : "string" | "number" + + const b = getFalsyPrimitive(stringOrBoolean); +>b : string | boolean +>getFalsyPrimitive(stringOrBoolean) : string | boolean +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>stringOrBoolean : "string" | "boolean" + + const c = getFalsyPrimitive(booleanOrNumber); +>c : number | boolean +>getFalsyPrimitive(booleanOrNumber) : number | boolean +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>booleanOrNumber : "number" | "boolean" + + const d = getFalsyPrimitive(stringOrBooleanOrNumber); +>d : string | number | boolean +>getFalsyPrimitive(stringOrBooleanOrNumber) : string | number | boolean +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>stringOrBooleanOrNumber : "string" | "number" | "boolean" +} + + + diff --git a/tests/baselines/reference/typeGuardsInIfStatement.errors.txt b/tests/baselines/reference/typeGuardsInIfStatement.errors.txt index cd9ae40932a..ac8dfb07887 100644 --- a/tests/baselines/reference/typeGuardsInIfStatement.errors.txt +++ b/tests/baselines/reference/typeGuardsInIfStatement.errors.txt @@ -1,10 +1,7 @@ -tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(22,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(31,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(49,10): error TS2354: No best common type exists among return expressions. tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(139,17): error TS2339: Property 'toString' does not exist on type 'never'. -==== tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts (4 errors) ==== +==== tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts (1 errors) ==== // In the true branch statement of an 'if' statement, // the type of a variable or parameter is narrowed by any type guard in the 'if' condition when true. // In the false branch statement of an 'if' statement, @@ -27,8 +24,6 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(139,17 } } function foo3(x: number | string) { - ~~~~ -!!! error TS2354: No best common type exists among return expressions. if (typeof x === "string") { x = "Hello"; return x; // string @@ -38,8 +33,6 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(139,17 } } function foo4(x: number | string) { - ~~~~ -!!! error TS2354: No best common type exists among return expressions. if (typeof x === "string") { return x; // string } @@ -58,8 +51,6 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(139,17 } } function foo6(x: number | string) { - ~~~~ -!!! error TS2354: No best common type exists among return expressions. if (typeof x === "string") { x = 10; return x; // number