diff --git a/tests/baselines/reference/stringLiteralCheckedInIf01.errors.txt b/tests/baselines/reference/stringLiteralCheckedInIf01.errors.txt deleted file mode 100644 index fb94cf6bc96..00000000000 --- a/tests/baselines/reference/stringLiteralCheckedInIf01.errors.txt +++ /dev/null @@ -1,26 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts(6,9): error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'. -tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts(9,14): error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts (2 errors) ==== - - type S = "a" | "b"; - type T = S[] | S; - - function f(foo: T) { - if (foo === "a") { - ~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'. - return foo; - } - else if (foo === "b") { - ~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'. - return foo; - } - else { - return (foo as S[])[0]; - } - - throw new Error("Unreachable code hit."); - } \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralCheckedInIf01.symbols b/tests/baselines/reference/stringLiteralCheckedInIf01.symbols new file mode 100644 index 00000000000..bd382a66ffa --- /dev/null +++ b/tests/baselines/reference/stringLiteralCheckedInIf01.symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts === + +type S = "a" | "b"; +>S : Symbol(S, Decl(stringLiteralCheckedInIf01.ts, 0, 0)) + +type T = S[] | S; +>T : Symbol(T, Decl(stringLiteralCheckedInIf01.ts, 1, 19)) +>S : Symbol(S, Decl(stringLiteralCheckedInIf01.ts, 0, 0)) +>S : Symbol(S, Decl(stringLiteralCheckedInIf01.ts, 0, 0)) + +function f(foo: T) { +>f : Symbol(f, Decl(stringLiteralCheckedInIf01.ts, 2, 17)) +>foo : Symbol(foo, Decl(stringLiteralCheckedInIf01.ts, 4, 11)) +>T : Symbol(T, Decl(stringLiteralCheckedInIf01.ts, 1, 19)) + + if (foo === "a") { +>foo : Symbol(foo, Decl(stringLiteralCheckedInIf01.ts, 4, 11)) + + return foo; +>foo : Symbol(foo, Decl(stringLiteralCheckedInIf01.ts, 4, 11)) + } + else if (foo === "b") { +>foo : Symbol(foo, Decl(stringLiteralCheckedInIf01.ts, 4, 11)) + + return foo; +>foo : Symbol(foo, Decl(stringLiteralCheckedInIf01.ts, 4, 11)) + } + else { + return (foo as S[])[0]; +>foo : Symbol(foo, Decl(stringLiteralCheckedInIf01.ts, 4, 11)) +>S : Symbol(S, Decl(stringLiteralCheckedInIf01.ts, 0, 0)) + } + + throw new Error("Unreachable code hit."); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} diff --git a/tests/baselines/reference/stringLiteralCheckedInIf01.types b/tests/baselines/reference/stringLiteralCheckedInIf01.types new file mode 100644 index 00000000000..1b3e663be74 --- /dev/null +++ b/tests/baselines/reference/stringLiteralCheckedInIf01.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts === + +type S = "a" | "b"; +>S : "a" | "b" + +type T = S[] | S; +>T : ("a" | "b")[] | "a" | "b" +>S : "a" | "b" +>S : "a" | "b" + +function f(foo: T) { +>f : (foo: ("a" | "b")[] | "a" | "b") => ("a" | "b")[] | "a" | "b" +>foo : ("a" | "b")[] | "a" | "b" +>T : ("a" | "b")[] | "a" | "b" + + if (foo === "a") { +>foo === "a" : boolean +>foo : ("a" | "b")[] | "a" | "b" +>"a" : string + + return foo; +>foo : ("a" | "b")[] | "a" | "b" + } + else if (foo === "b") { +>foo === "b" : boolean +>foo : ("a" | "b")[] | "a" | "b" +>"b" : string + + return foo; +>foo : ("a" | "b")[] | "a" | "b" + } + else { + return (foo as S[])[0]; +>(foo as S[])[0] : "a" | "b" +>(foo as S[]) : ("a" | "b")[] +>foo as S[] : ("a" | "b")[] +>foo : ("a" | "b")[] | "a" | "b" +>S : "a" | "b" +>0 : number + } + + throw new Error("Unreachable code hit."); +>new Error("Unreachable code hit.") : Error +>Error : ErrorConstructor +>"Unreachable code hit." : string +} diff --git a/tests/baselines/reference/stringLiteralCheckedInIf02.errors.txt b/tests/baselines/reference/stringLiteralCheckedInIf02.errors.txt deleted file mode 100644 index ced5adf6263..00000000000 --- a/tests/baselines/reference/stringLiteralCheckedInIf02.errors.txt +++ /dev/null @@ -1,27 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf02.ts(6,12): error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'. -tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf02.ts(6,25): error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf02.ts (2 errors) ==== - - type S = "a" | "b"; - type T = S[] | S; - - function isS(t: T): t is S { - return t === "a" || t === "b"; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'. - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'. - } - - function f(foo: T) { - if (isS(foo)) { - return foo; - } - else { - return foo[0]; - } - - throw new Error("Unreachable code hit."); - } \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralCheckedInIf02.symbols b/tests/baselines/reference/stringLiteralCheckedInIf02.symbols new file mode 100644 index 00000000000..84a19936371 --- /dev/null +++ b/tests/baselines/reference/stringLiteralCheckedInIf02.symbols @@ -0,0 +1,42 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf02.ts === + +type S = "a" | "b"; +>S : Symbol(S, Decl(stringLiteralCheckedInIf02.ts, 0, 0)) + +type T = S[] | S; +>T : Symbol(T, Decl(stringLiteralCheckedInIf02.ts, 1, 19)) +>S : Symbol(S, Decl(stringLiteralCheckedInIf02.ts, 0, 0)) +>S : Symbol(S, Decl(stringLiteralCheckedInIf02.ts, 0, 0)) + +function isS(t: T): t is S { +>isS : Symbol(isS, Decl(stringLiteralCheckedInIf02.ts, 2, 17)) +>t : Symbol(t, Decl(stringLiteralCheckedInIf02.ts, 4, 13)) +>T : Symbol(T, Decl(stringLiteralCheckedInIf02.ts, 1, 19)) +>t : Symbol(t, Decl(stringLiteralCheckedInIf02.ts, 4, 13)) +>S : Symbol(S, Decl(stringLiteralCheckedInIf02.ts, 0, 0)) + + return t === "a" || t === "b"; +>t : Symbol(t, Decl(stringLiteralCheckedInIf02.ts, 4, 13)) +>t : Symbol(t, Decl(stringLiteralCheckedInIf02.ts, 4, 13)) +} + +function f(foo: T) { +>f : Symbol(f, Decl(stringLiteralCheckedInIf02.ts, 6, 1)) +>foo : Symbol(foo, Decl(stringLiteralCheckedInIf02.ts, 8, 11)) +>T : Symbol(T, Decl(stringLiteralCheckedInIf02.ts, 1, 19)) + + if (isS(foo)) { +>isS : Symbol(isS, Decl(stringLiteralCheckedInIf02.ts, 2, 17)) +>foo : Symbol(foo, Decl(stringLiteralCheckedInIf02.ts, 8, 11)) + + return foo; +>foo : Symbol(foo, Decl(stringLiteralCheckedInIf02.ts, 8, 11)) + } + else { + return foo[0]; +>foo : Symbol(foo, Decl(stringLiteralCheckedInIf02.ts, 8, 11)) + } + + throw new Error("Unreachable code hit."); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} diff --git a/tests/baselines/reference/stringLiteralCheckedInIf02.types b/tests/baselines/reference/stringLiteralCheckedInIf02.types new file mode 100644 index 00000000000..005ec356f39 --- /dev/null +++ b/tests/baselines/reference/stringLiteralCheckedInIf02.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf02.ts === + +type S = "a" | "b"; +>S : "a" | "b" + +type T = S[] | S; +>T : ("a" | "b")[] | "a" | "b" +>S : "a" | "b" +>S : "a" | "b" + +function isS(t: T): t is S { +>isS : (t: ("a" | "b")[] | "a" | "b") => t is "a" | "b" +>t : ("a" | "b")[] | "a" | "b" +>T : ("a" | "b")[] | "a" | "b" +>t : any +>S : "a" | "b" + + return t === "a" || t === "b"; +>t === "a" || t === "b" : boolean +>t === "a" : boolean +>t : ("a" | "b")[] | "a" | "b" +>"a" : string +>t === "b" : boolean +>t : ("a" | "b")[] | "a" | "b" +>"b" : string +} + +function f(foo: T) { +>f : (foo: ("a" | "b")[] | "a" | "b") => "a" | "b" +>foo : ("a" | "b")[] | "a" | "b" +>T : ("a" | "b")[] | "a" | "b" + + if (isS(foo)) { +>isS(foo) : boolean +>isS : (t: ("a" | "b")[] | "a" | "b") => t is "a" | "b" +>foo : ("a" | "b")[] | "a" | "b" + + return foo; +>foo : "a" | "b" + } + else { + return foo[0]; +>foo[0] : "a" | "b" +>foo : ("a" | "b")[] +>0 : number + } + + throw new Error("Unreachable code hit."); +>new Error("Unreachable code hit.") : Error +>Error : ErrorConstructor +>"Unreachable code hit." : string +} diff --git a/tests/baselines/reference/stringLiteralMatchedInSwitch01.errors.txt b/tests/baselines/reference/stringLiteralMatchedInSwitch01.errors.txt deleted file mode 100644 index 17e690715a1..00000000000 --- a/tests/baselines/reference/stringLiteralMatchedInSwitch01.errors.txt +++ /dev/null @@ -1,26 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralMatchedInSwitch01.ts(7,10): error TS2322: Type 'string' is not assignable to type '("a" | "b")[] | "a" | "b"'. - Type 'string' is not assignable to type '"b"'. -tests/cases/conformance/types/stringLiteral/stringLiteralMatchedInSwitch01.ts(8,10): error TS2322: Type 'string' is not assignable to type '("a" | "b")[] | "a" | "b"'. - Type 'string' is not assignable to type '"b"'. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralMatchedInSwitch01.ts (2 errors) ==== - - type S = "a" | "b"; - type T = S[] | S; - - var foo: T; - switch (foo) { - case "a": - ~~~ -!!! error TS2322: Type 'string' is not assignable to type '("a" | "b")[] | "a" | "b"'. -!!! error TS2322: Type 'string' is not assignable to type '"b"'. - case "b": - ~~~ -!!! error TS2322: Type 'string' is not assignable to type '("a" | "b")[] | "a" | "b"'. -!!! error TS2322: Type 'string' is not assignable to type '"b"'. - break; - default: - foo = (foo as S[])[0]; - break; - } \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralMatchedInSwitch01.symbols b/tests/baselines/reference/stringLiteralMatchedInSwitch01.symbols new file mode 100644 index 00000000000..0323371c307 --- /dev/null +++ b/tests/baselines/reference/stringLiteralMatchedInSwitch01.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralMatchedInSwitch01.ts === + +type S = "a" | "b"; +>S : Symbol(S, Decl(stringLiteralMatchedInSwitch01.ts, 0, 0)) + +type T = S[] | S; +>T : Symbol(T, Decl(stringLiteralMatchedInSwitch01.ts, 1, 19)) +>S : Symbol(S, Decl(stringLiteralMatchedInSwitch01.ts, 0, 0)) +>S : Symbol(S, Decl(stringLiteralMatchedInSwitch01.ts, 0, 0)) + +var foo: T; +>foo : Symbol(foo, Decl(stringLiteralMatchedInSwitch01.ts, 4, 3)) +>T : Symbol(T, Decl(stringLiteralMatchedInSwitch01.ts, 1, 19)) + +switch (foo) { +>foo : Symbol(foo, Decl(stringLiteralMatchedInSwitch01.ts, 4, 3)) + + case "a": + case "b": + break; + default: + foo = (foo as S[])[0]; +>foo : Symbol(foo, Decl(stringLiteralMatchedInSwitch01.ts, 4, 3)) +>foo : Symbol(foo, Decl(stringLiteralMatchedInSwitch01.ts, 4, 3)) +>S : Symbol(S, Decl(stringLiteralMatchedInSwitch01.ts, 0, 0)) + + break; +} diff --git a/tests/baselines/reference/stringLiteralMatchedInSwitch01.types b/tests/baselines/reference/stringLiteralMatchedInSwitch01.types new file mode 100644 index 00000000000..cfbb77e07e0 --- /dev/null +++ b/tests/baselines/reference/stringLiteralMatchedInSwitch01.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralMatchedInSwitch01.ts === + +type S = "a" | "b"; +>S : "a" | "b" + +type T = S[] | S; +>T : ("a" | "b")[] | "a" | "b" +>S : "a" | "b" +>S : "a" | "b" + +var foo: T; +>foo : ("a" | "b")[] | "a" | "b" +>T : ("a" | "b")[] | "a" | "b" + +switch (foo) { +>foo : ("a" | "b")[] | "a" | "b" + + case "a": +>"a" : string + + case "b": +>"b" : string + + break; + default: + foo = (foo as S[])[0]; +>foo = (foo as S[])[0] : "a" | "b" +>foo : ("a" | "b")[] | "a" | "b" +>(foo as S[])[0] : "a" | "b" +>(foo as S[]) : ("a" | "b")[] +>foo as S[] : ("a" | "b")[] +>foo : ("a" | "b")[] | "a" | "b" +>S : "a" | "b" +>0 : number + + break; +} diff --git a/tests/baselines/reference/stringLiteralTypeAssertion01.errors.txt b/tests/baselines/reference/stringLiteralTypeAssertion01.errors.txt deleted file mode 100644 index 867ad80ee7f..00000000000 --- a/tests/baselines/reference/stringLiteralTypeAssertion01.errors.txt +++ /dev/null @@ -1,55 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(22,5): error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. - Type 'string' is not assignable to type '"b"'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(23,5): error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. - Type 'string' is not assignable to type '"b"'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(30,7): error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. - Type '("a" | "b")[]' is not assignable to type 'string'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(31,7): error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. - Type '("a" | "b")[]' is not assignable to type 'string'. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts (4 errors) ==== - - type S = "a" | "b"; - type T = S[] | S; - - var s: S; - var t: T; - var str: string; - - //////////////// - - s = t; - s = t as S; - - s = str; - s = str as S; - - //////////////// - - t = s; - t = s as T; - - t = str; - ~~~~~~ -!!! error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. -!!! error TS2352: Type 'string' is not assignable to type '"b"'. - t = str as T; - ~~~~~~~~ -!!! error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. -!!! error TS2352: Type 'string' is not assignable to type '"b"'. - - //////////////// - - str = s; - str = s as string; - - str = t; - ~~~~~~~~~ -!!! error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. -!!! error TS2352: Type '("a" | "b")[]' is not assignable to type 'string'. - str = t as string; - ~~~~~~~~~~~ -!!! error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. -!!! error TS2352: Type '("a" | "b")[]' is not assignable to type 'string'. - \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypeAssertion01.symbols b/tests/baselines/reference/stringLiteralTypeAssertion01.symbols new file mode 100644 index 00000000000..1491a32b6f8 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypeAssertion01.symbols @@ -0,0 +1,83 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts === + +type S = "a" | "b"; +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) + +type T = S[] | S; +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) + +var s: S; +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) + +var t: T; +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) + +var str: string; +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) + +//////////////// + +s = t; +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) + +s = t as S; +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) + +s = str; +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) + +s = str as S; +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) + +//////////////// + +t = s; +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) + +t = s as T; +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) + +t = str; +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) + +t = str as T; +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) + +//////////////// + +str = s; +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) + +str = s as string; +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) + +str = t; +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) + +str = t as string; +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) + diff --git a/tests/baselines/reference/stringLiteralTypeAssertion01.types b/tests/baselines/reference/stringLiteralTypeAssertion01.types new file mode 100644 index 00000000000..f70313f8347 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypeAssertion01.types @@ -0,0 +1,107 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts === + +type S = "a" | "b"; +>S : "a" | "b" + +type T = S[] | S; +>T : ("a" | "b")[] | "a" | "b" +>S : "a" | "b" +>S : "a" | "b" + +var s: S; +>s : "a" | "b" +>S : "a" | "b" + +var t: T; +>t : ("a" | "b")[] | "a" | "b" +>T : ("a" | "b")[] | "a" | "b" + +var str: string; +>str : string + +//////////////// + +s = t; +>s = t : "a" | "b" +>s : "a" | "b" +>t : "a" | "b" +>S : "a" | "b" +>t : ("a" | "b")[] | "a" | "b" + +s = t as S; +>s = t as S : "a" | "b" +>s : "a" | "b" +>t as S : "a" | "b" +>t : ("a" | "b")[] | "a" | "b" +>S : "a" | "b" + +s = str; +>s = str : "a" | "b" +>s : "a" | "b" +>str : "a" | "b" +>S : "a" | "b" +>str : string + +s = str as S; +>s = str as S : "a" | "b" +>s : "a" | "b" +>str as S : "a" | "b" +>str : string +>S : "a" | "b" + +//////////////// + +t = s; +>t = s : ("a" | "b")[] | "a" | "b" +>t : ("a" | "b")[] | "a" | "b" +>s : ("a" | "b")[] | "a" | "b" +>T : ("a" | "b")[] | "a" | "b" +>s : "a" | "b" + +t = s as T; +>t = s as T : ("a" | "b")[] | "a" | "b" +>t : ("a" | "b")[] | "a" | "b" +>s as T : ("a" | "b")[] | "a" | "b" +>s : "a" | "b" +>T : ("a" | "b")[] | "a" | "b" + +t = str; +>t = str : ("a" | "b")[] | "a" | "b" +>t : ("a" | "b")[] | "a" | "b" +>str : ("a" | "b")[] | "a" | "b" +>T : ("a" | "b")[] | "a" | "b" +>str : string + +t = str as T; +>t = str as T : ("a" | "b")[] | "a" | "b" +>t : ("a" | "b")[] | "a" | "b" +>str as T : ("a" | "b")[] | "a" | "b" +>str : string +>T : ("a" | "b")[] | "a" | "b" + +//////////////// + +str = s; +>str = s : string +>str : string +>s : string +>s : "a" | "b" + +str = s as string; +>str = s as string : string +>str : string +>s as string : string +>s : "a" | "b" + +str = t; +>str = t : string +>str : string +>t : string +>t : ("a" | "b")[] | "a" | "b" + +str = t as string; +>str = t as string : string +>str : string +>t as string : string +>t : ("a" | "b")[] | "a" | "b" + diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.errors.txt b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.errors.txt deleted file mode 100644 index 74249b178d6..00000000000 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.errors.txt +++ /dev/null @@ -1,29 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(7,5): error TS2365: Operator '===' cannot be applied to types '"foo" | "bar" | number' and 'string'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(10,10): error TS2365: Operator '!==' cannot be applied to types '"foo" | "bar" | number' and 'string'. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts (2 errors) ==== - - type T = number | "foo" | "bar"; - - var x: "foo" | "bar" | number; - var y: T = "bar"; - - if (x === "foo") { - ~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '"foo" | "bar" | number' and 'string'. - let a = x; - } - else if (x !== "bar") { - ~~~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types '"foo" | "bar" | number' and 'string'. - let b = x || y; - } - else { - let c = x; - let d = y; - let e: (typeof x) | (typeof y) = c || d; - } - - x = y; - y = x; \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.symbols b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.symbols new file mode 100644 index 00000000000..df5498d9a59 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.symbols @@ -0,0 +1,52 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts === + +type T = number | "foo" | "bar"; +>T : Symbol(T, Decl(stringLiteralTypesInUnionTypes03.ts, 0, 0)) + +var x: "foo" | "bar" | number; +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes03.ts, 3, 3)) + +var y: T = "bar"; +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes03.ts, 4, 3)) +>T : Symbol(T, Decl(stringLiteralTypesInUnionTypes03.ts, 0, 0)) + +if (x === "foo") { +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes03.ts, 3, 3)) + + let a = x; +>a : Symbol(a, Decl(stringLiteralTypesInUnionTypes03.ts, 7, 7)) +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes03.ts, 3, 3)) +} +else if (x !== "bar") { +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes03.ts, 3, 3)) + + let b = x || y; +>b : Symbol(b, Decl(stringLiteralTypesInUnionTypes03.ts, 10, 7)) +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes03.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes03.ts, 4, 3)) +} +else { + let c = x; +>c : Symbol(c, Decl(stringLiteralTypesInUnionTypes03.ts, 13, 7)) +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes03.ts, 3, 3)) + + let d = y; +>d : Symbol(d, Decl(stringLiteralTypesInUnionTypes03.ts, 14, 7)) +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes03.ts, 4, 3)) + + let e: (typeof x) | (typeof y) = c || d; +>e : Symbol(e, Decl(stringLiteralTypesInUnionTypes03.ts, 15, 7)) +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes03.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes03.ts, 4, 3)) +>c : Symbol(c, Decl(stringLiteralTypesInUnionTypes03.ts, 13, 7)) +>d : Symbol(d, Decl(stringLiteralTypesInUnionTypes03.ts, 14, 7)) +} + +x = y; +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes03.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes03.ts, 4, 3)) + +y = x; +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes03.ts, 4, 3)) +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes03.ts, 3, 3)) + diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types new file mode 100644 index 00000000000..5fca6e69be9 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types @@ -0,0 +1,61 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts === + +type T = number | "foo" | "bar"; +>T : number | "foo" | "bar" + +var x: "foo" | "bar" | number; +>x : "foo" | "bar" | number + +var y: T = "bar"; +>y : number | "foo" | "bar" +>T : number | "foo" | "bar" +>"bar" : "bar" + +if (x === "foo") { +>x === "foo" : boolean +>x : "foo" | "bar" | number +>"foo" : string + + let a = x; +>a : "foo" | "bar" | number +>x : "foo" | "bar" | number +} +else if (x !== "bar") { +>x !== "bar" : boolean +>x : "foo" | "bar" | number +>"bar" : string + + let b = x || y; +>b : "foo" | "bar" | number +>x || y : "foo" | "bar" | number +>x : "foo" | "bar" | number +>y : number | "foo" | "bar" +} +else { + let c = x; +>c : "foo" | "bar" | number +>x : "foo" | "bar" | number + + let d = y; +>d : number | "foo" | "bar" +>y : number | "foo" | "bar" + + let e: (typeof x) | (typeof y) = c || d; +>e : "foo" | "bar" | number +>x : "foo" | "bar" | number +>y : number | "foo" | "bar" +>c || d : "foo" | "bar" | number +>c : "foo" | "bar" | number +>d : number | "foo" | "bar" +} + +x = y; +>x = y : number | "foo" | "bar" +>x : "foo" | "bar" | number +>y : number | "foo" | "bar" + +y = x; +>y = x : "foo" | "bar" | number +>y : number | "foo" | "bar" +>x : "foo" | "bar" | number + diff --git a/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt b/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt index 92afe67df0c..69dd6c2f6a9 100644 --- a/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt @@ -7,12 +7,9 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperato tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(13,11): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(14,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(15,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(16,9): error TS2365: Operator '<' cannot be applied to types '"ABC"' and '"XYZ"'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(17,9): error TS2365: Operator '===' cannot be applied to types '"ABC"' and '"XYZ"'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(18,9): error TS2365: Operator '!=' cannot be applied to types '"ABC"' and '"XYZ"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts (12 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts (9 errors) ==== let abc: "ABC" = "ABC"; let xyz: "XYZ" = "XYZ"; @@ -47,11 +44,5 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperato ~~~~~~~~~~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. let j = abc < xyz; - ~~~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types '"ABC"' and '"XYZ"'. let k = abc === xyz; - ~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '"ABC"' and '"XYZ"'. - let l = abc != xyz; - ~~~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types '"ABC"' and '"XYZ"'. \ No newline at end of file + let l = abc != xyz; \ No newline at end of file