diff --git a/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.errors.txt b/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.errors.txt deleted file mode 100644 index 707e68c2c45..00000000000 --- a/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.errors.txt +++ /dev/null @@ -1,34 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IncompleteMemberVariables/parserErrorRecovery_IncompleteMemberVariable1.ts(12,21): error TS1110: Type expected. - - -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IncompleteMemberVariables/parserErrorRecovery_IncompleteMemberVariable1.ts (1 errors) ==== - // Interface - interface IPoint { - getDist(): number; - } - - // Module - module Shapes { - - // Class - export class Point implements IPoint { - - public con: "hello"; - ~~~~~~~ -!!! error TS1110: Type expected. - // Constructor - constructor (public x: number, public y: number) { } - - // Instance member - getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } - - // Static member - static origin = new Point(0, 0); - } - - } - - // Local variables - var p: IPoint = new Shapes.Point(3, 4); - var dist = p.getDist(); - \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.js b/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.js index ae2509c3f49..8055cd9d494 100644 --- a/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.js +++ b/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.js @@ -38,7 +38,6 @@ var Shapes; function Point(x, y) { this.x = x; this.y = y; - this.con = "hello"; } // Instance member Point.prototype.getDist = function () { return Math.sqrt(this.x * this.x + this.y * this.y); }; diff --git a/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.symbols b/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.symbols new file mode 100644 index 00000000000..db9cefbf642 --- /dev/null +++ b/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.symbols @@ -0,0 +1,67 @@ +=== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IncompleteMemberVariables/parserErrorRecovery_IncompleteMemberVariable1.ts === +// Interface +interface IPoint { +>IPoint : Symbol(IPoint, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 0, 0)) + + getDist(): number; +>getDist : Symbol(getDist, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 1, 18)) +} + +// Module +module Shapes { +>Shapes : Symbol(Shapes, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 3, 1)) + + // Class + export class Point implements IPoint { +>Point : Symbol(Point, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 6, 15)) +>IPoint : Symbol(IPoint, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 0, 0)) + + public con: "hello"; +>con : Symbol(con, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 9, 42)) + + // Constructor + constructor (public x: number, public y: number) { } +>x : Symbol(x, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 13, 21)) +>y : Symbol(y, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 13, 38)) + + // Instance member + getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } +>getDist : Symbol(getDist, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 13, 60)) +>Math.sqrt : Symbol(Math.sqrt, Decl(lib.d.ts, 620, 27)) +>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11)) +>sqrt : Symbol(Math.sqrt, Decl(lib.d.ts, 620, 27)) +>this.x : Symbol(x, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 13, 21)) +>this : Symbol(Point, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 6, 15)) +>x : Symbol(x, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 13, 21)) +>this.x : Symbol(x, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 13, 21)) +>this : Symbol(Point, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 6, 15)) +>x : Symbol(x, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 13, 21)) +>this.y : Symbol(y, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 13, 38)) +>this : Symbol(Point, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 6, 15)) +>y : Symbol(y, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 13, 38)) +>this.y : Symbol(y, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 13, 38)) +>this : Symbol(Point, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 6, 15)) +>y : Symbol(y, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 13, 38)) + + // Static member + static origin = new Point(0, 0); +>origin : Symbol(Point.origin, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 16, 74)) +>Point : Symbol(Point, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 6, 15)) + } + +} + +// Local variables +var p: IPoint = new Shapes.Point(3, 4); +>p : Symbol(p, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 25, 3)) +>IPoint : Symbol(IPoint, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 0, 0)) +>Shapes.Point : Symbol(Shapes.Point, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 6, 15)) +>Shapes : Symbol(Shapes, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 3, 1)) +>Point : Symbol(Shapes.Point, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 6, 15)) + +var dist = p.getDist(); +>dist : Symbol(dist, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 26, 3)) +>p.getDist : Symbol(IPoint.getDist, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 1, 18)) +>p : Symbol(p, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 25, 3)) +>getDist : Symbol(IPoint.getDist, Decl(parserErrorRecovery_IncompleteMemberVariable1.ts, 1, 18)) + diff --git a/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.types b/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.types new file mode 100644 index 00000000000..bb51151cfd7 --- /dev/null +++ b/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.types @@ -0,0 +1,78 @@ +=== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IncompleteMemberVariables/parserErrorRecovery_IncompleteMemberVariable1.ts === +// Interface +interface IPoint { +>IPoint : IPoint + + getDist(): number; +>getDist : () => number +} + +// Module +module Shapes { +>Shapes : typeof Shapes + + // Class + export class Point implements IPoint { +>Point : Point +>IPoint : IPoint + + public con: "hello"; +>con : "hello" + + // Constructor + constructor (public x: number, public y: number) { } +>x : number +>y : number + + // Instance member + getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } +>getDist : () => number +>Math.sqrt(this.x * this.x + this.y * this.y) : number +>Math.sqrt : (x: number) => number +>Math : Math +>sqrt : (x: number) => number +>this.x * this.x + this.y * this.y : number +>this.x * this.x : number +>this.x : number +>this : Point +>x : number +>this.x : number +>this : Point +>x : number +>this.y * this.y : number +>this.y : number +>this : Point +>y : number +>this.y : number +>this : Point +>y : number + + // Static member + static origin = new Point(0, 0); +>origin : Point +>new Point(0, 0) : Point +>Point : typeof Point +>0 : number +>0 : number + } + +} + +// Local variables +var p: IPoint = new Shapes.Point(3, 4); +>p : IPoint +>IPoint : IPoint +>new Shapes.Point(3, 4) : Shapes.Point +>Shapes.Point : typeof Shapes.Point +>Shapes : typeof Shapes +>Point : typeof Shapes.Point +>3 : number +>4 : number + +var dist = p.getDist(); +>dist : number +>p.getDist() : number +>p.getDist : () => number +>p : IPoint +>getDist : () => number + diff --git a/tests/baselines/reference/stringLiteralType.errors.txt b/tests/baselines/reference/stringLiteralType.errors.txt deleted file mode 100644 index 275db139cf7..00000000000 --- a/tests/baselines/reference/stringLiteralType.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/conformance/types/primitives/stringLiteral/stringLiteralType.ts(1,8): error TS1110: Type expected. - - -==== tests/cases/conformance/types/primitives/stringLiteral/stringLiteralType.ts (1 errors) ==== - var x: 'hi'; - ~~~~ -!!! error TS1110: Type expected. - - function f(x: 'hi'); - function f(x: string); - function f(x: any) { - } \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralType.js b/tests/baselines/reference/stringLiteralType.js index 35f35f1cbef..a6926453c47 100644 --- a/tests/baselines/reference/stringLiteralType.js +++ b/tests/baselines/reference/stringLiteralType.js @@ -7,6 +7,6 @@ function f(x: any) { } //// [stringLiteralType.js] -var x = 'hi'; +var x; function f(x) { } diff --git a/tests/baselines/reference/stringLiteralType.symbols b/tests/baselines/reference/stringLiteralType.symbols new file mode 100644 index 00000000000..687d3052442 --- /dev/null +++ b/tests/baselines/reference/stringLiteralType.symbols @@ -0,0 +1,16 @@ +=== tests/cases/conformance/types/primitives/stringLiteral/stringLiteralType.ts === +var x: 'hi'; +>x : Symbol(x, Decl(stringLiteralType.ts, 0, 3)) + +function f(x: 'hi'); +>f : Symbol(f, Decl(stringLiteralType.ts, 0, 12), Decl(stringLiteralType.ts, 2, 20), Decl(stringLiteralType.ts, 3, 22)) +>x : Symbol(x, Decl(stringLiteralType.ts, 2, 11)) + +function f(x: string); +>f : Symbol(f, Decl(stringLiteralType.ts, 0, 12), Decl(stringLiteralType.ts, 2, 20), Decl(stringLiteralType.ts, 3, 22)) +>x : Symbol(x, Decl(stringLiteralType.ts, 3, 11)) + +function f(x: any) { +>f : Symbol(f, Decl(stringLiteralType.ts, 0, 12), Decl(stringLiteralType.ts, 2, 20), Decl(stringLiteralType.ts, 3, 22)) +>x : Symbol(x, Decl(stringLiteralType.ts, 4, 11)) +} diff --git a/tests/baselines/reference/stringLiteralType.types b/tests/baselines/reference/stringLiteralType.types new file mode 100644 index 00000000000..5d2e13c4ba5 --- /dev/null +++ b/tests/baselines/reference/stringLiteralType.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/types/primitives/stringLiteral/stringLiteralType.ts === +var x: 'hi'; +>x : 'hi' + +function f(x: 'hi'); +>f : { (x: 'hi'): any; (x: string): any; } +>x : 'hi' + +function f(x: string); +>f : { (x: 'hi'): any; (x: string): any; } +>x : string + +function f(x: any) { +>f : { (x: 'hi'): any; (x: string): any; } +>x : any +} diff --git a/tests/baselines/reference/stringLiteralTypesAsTags01.errors.txt b/tests/baselines/reference/stringLiteralTypesAsTags01.errors.txt index 292cc8ea5b7..df05e25304f 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags01.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesAsTags01.errors.txt @@ -1,30 +1,15 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(2,12): error TS4081: Exported type alias 'Kind' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(2,13): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(2,13): 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/stringLiteralTypesAsTags01.ts(2,19): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(9,10): error TS4033: Property 'kind' of exported interface has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(9,11): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(14,10): error TS4033: Property 'kind' of exported interface has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(14,11): error TS1110: Type expected. tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(18,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(19,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(20,10): error TS2394: Overload signature is not compatible with function implementation. tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(22,21): error TS2304: Cannot find name 'is'. tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(25,5): error TS2322: Type '{ kind: string; a: number; }' is not assignable to type 'A'. - Property '"A"' is missing in type '{ kind: string; a: number; }'. + Types of property 'kind' are incompatible. + Type 'string' is not assignable to type '"A"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts (13 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts (5 errors) ==== type Kind = "A" | "B" - -!!! error TS4081: Exported type alias 'Kind' has or is using private name ''. - ~~~ -!!! error TS1110: Type expected. - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. interface Entity { kind: Kind; @@ -32,19 +17,11 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(25,5): interface A extends Entity { kind: "A"; - -!!! error TS4033: Property 'kind' of exported interface has or is using private name ''. - ~~~ -!!! error TS1110: Type expected. a: number; } interface B extends Entity { kind: "B"; - -!!! error TS4033: Property 'kind' of exported interface has or is using private name ''. - ~~~ -!!! error TS1110: Type expected. b: string; } @@ -66,7 +43,8 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(25,5): let x: A = { ~ !!! error TS2322: Type '{ kind: string; a: number; }' is not assignable to type 'A'. -!!! error TS2322: Property '"A"' is missing in type '{ kind: string; a: number; }'. +!!! error TS2322: Types of property 'kind' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"A"'. kind: "A", a: 100, } diff --git a/tests/baselines/reference/stringLiteralTypesAsTags01.js b/tests/baselines/reference/stringLiteralTypesAsTags01.js index 2ce20607790..3fe33ace487 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags01.js +++ b/tests/baselines/reference/stringLiteralTypesAsTags01.js @@ -43,7 +43,6 @@ else { } //// [stringLiteralTypesAsTags01.js] -"A" | "B"; function hasKind(entity, kind) { return kind === is; } @@ -63,3 +62,22 @@ if (!hasKind(x, "B")) { else { var d = x; } + + +//// [stringLiteralTypesAsTags01.d.ts] +declare type Kind = "A" | "B"; +interface Entity { + kind: Kind; +} +interface A extends Entity { + kind: "A"; + a: number; +} +interface B extends Entity { + kind: "B"; + b: string; +} +declare function hasKind(entity: Entity, kind: "A"): entity is A; +declare function hasKind(entity: Entity, kind: "B"): entity is B; +declare function hasKind(entity: Entity, kind: Kind): entity is Entity; +declare let x: A; diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.errors.txt b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.errors.txt index fcc13629ceb..14d0a892f55 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.errors.txt @@ -1,47 +1,21 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(2,9): error TS4081: Exported type alias 'T' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(2,10): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(2,10): 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/stringLiteralTypesInUnionTypes01.ts(2,18): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(2,26): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(4,7): error TS4025: Exported variable 'x' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(4,8): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(4,8): 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/stringLiteralTypesInUnionTypes01.ts(4,16): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(4,24): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(4,30): error TS1005: ',' expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(4,32): error TS1134: Variable declaration expected. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(4,5): error TS2322: Type 'string' is not assignable to type '"foo" | "bar" | "baz"'. + Type 'string' is not assignable to type '"baz"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(5,5): error TS2322: Type 'string' is not assignable to type '"foo" | "bar" | "baz"'. + Type 'string' is not assignable to type '"baz"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts (12 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts (2 errors) ==== type T = "foo" | "bar" | "baz"; - -!!! error TS4081: Exported type alias 'T' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. - ~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. var x: "foo" | "bar" | "baz" = "foo"; - -!!! error TS4025: Exported variable 'x' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. - ~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~ -!!! error TS1005: ',' expected. - ~~~~~ -!!! error TS1134: Variable declaration expected. + ~ +!!! error TS2322: Type 'string' is not assignable to type '"foo" | "bar" | "baz"'. +!!! error TS2322: Type 'string' is not assignable to type '"baz"'. var y: T = "bar"; + ~ +!!! error TS2322: Type 'string' is not assignable to type '"foo" | "bar" | "baz"'. +!!! error TS2322: Type 'string' is not assignable to type '"baz"'. if (x === "foo") { let a = x; diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.js b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.js index 4eaaec42ceb..d970310d68e 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.js +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.js @@ -21,9 +21,7 @@ x = y; y = x; //// [stringLiteralTypesInUnionTypes01.js] -"foo" | "bar" | "baz"; -var x = "foo" | "bar" | "baz"; -"foo"; +var x = "foo"; var y = "bar"; if (x === "foo") { var a = x; @@ -38,3 +36,9 @@ else { } x = y; y = x; + + +//// [stringLiteralTypesInUnionTypes01.d.ts] +declare type T = "foo" | "bar" | "baz"; +declare var x: "foo" | "bar" | "baz"; +declare var y: T; diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.errors.txt b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.errors.txt deleted file mode 100644 index dc8523051aa..00000000000 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.errors.txt +++ /dev/null @@ -1,62 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts(2,18): error TS4081: Exported type alias 'T' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts(2,19): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts(2,19): 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/stringLiteralTypesInUnionTypes02.ts(2,27): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts(2,35): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts(4,7): error TS4025: Exported variable 'x' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts(4,8): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts(4,8): 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/stringLiteralTypesInUnionTypes02.ts(4,16): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts(4,24): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts(4,32): error TS2304: Cannot find name 'string'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts(4,39): error TS1005: ',' expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts(4,41): error TS1134: Variable declaration expected. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts (13 errors) ==== - - type T = string | "foo" | "bar" | "baz"; - -!!! error TS4081: Exported type alias 'T' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. - ~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - - var x: "foo" | "bar" | "baz" | string = "foo"; - -!!! error TS4025: Exported variable 'x' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. - ~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~~ -!!! error TS2304: Cannot find name 'string'. - ~ -!!! error TS1005: ',' expected. - ~~~~~ -!!! error TS1134: Variable declaration expected. - var y: T = "bar"; - - if (x === "foo") { - let a = x; - } - else if (x !== "bar") { - 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/stringLiteralTypesInUnionTypes02.js b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.js index 19b309980f8..19b9c837c9d 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.js +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.js @@ -21,9 +21,7 @@ x = y; y = x; //// [stringLiteralTypesInUnionTypes02.js] -"foo" | "bar" | "baz"; -var x = "foo" | "bar" | "baz" | string; -"foo"; +var x = "foo"; var y = "bar"; if (x === "foo") { var a = x; @@ -38,3 +36,9 @@ else { } x = y; y = x; + + +//// [stringLiteralTypesInUnionTypes02.d.ts] +declare type T = string | "foo" | "bar" | "baz"; +declare var x: "foo" | "bar" | "baz" | string; +declare var y: T; diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.symbols b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.symbols new file mode 100644 index 00000000000..c9b31dc710a --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.symbols @@ -0,0 +1,52 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts === + +type T = string | "foo" | "bar" | "baz"; +>T : Symbol(T, Decl(stringLiteralTypesInUnionTypes02.ts, 0, 0)) + +var x: "foo" | "bar" | "baz" | string = "foo"; +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes02.ts, 3, 3)) + +var y: T = "bar"; +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes02.ts, 4, 3)) +>T : Symbol(T, Decl(stringLiteralTypesInUnionTypes02.ts, 0, 0)) + +if (x === "foo") { +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes02.ts, 3, 3)) + + let a = x; +>a : Symbol(a, Decl(stringLiteralTypesInUnionTypes02.ts, 7, 7)) +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes02.ts, 3, 3)) +} +else if (x !== "bar") { +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes02.ts, 3, 3)) + + let b = x || y; +>b : Symbol(b, Decl(stringLiteralTypesInUnionTypes02.ts, 10, 7)) +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes02.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes02.ts, 4, 3)) +} +else { + let c = x; +>c : Symbol(c, Decl(stringLiteralTypesInUnionTypes02.ts, 13, 7)) +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes02.ts, 3, 3)) + + let d = y; +>d : Symbol(d, Decl(stringLiteralTypesInUnionTypes02.ts, 14, 7)) +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes02.ts, 4, 3)) + + let e: (typeof x) | (typeof y) = c || d; +>e : Symbol(e, Decl(stringLiteralTypesInUnionTypes02.ts, 15, 7)) +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes02.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes02.ts, 4, 3)) +>c : Symbol(c, Decl(stringLiteralTypesInUnionTypes02.ts, 13, 7)) +>d : Symbol(d, Decl(stringLiteralTypesInUnionTypes02.ts, 14, 7)) +} + +x = y; +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes02.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes02.ts, 4, 3)) + +y = x; +>y : Symbol(y, Decl(stringLiteralTypesInUnionTypes02.ts, 4, 3)) +>x : Symbol(x, Decl(stringLiteralTypesInUnionTypes02.ts, 3, 3)) + diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types new file mode 100644 index 00000000000..569edc77815 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types @@ -0,0 +1,62 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts === + +type T = string | "foo" | "bar" | "baz"; +>T : string | "foo" | "bar" | "baz" + +var x: "foo" | "bar" | "baz" | string = "foo"; +>x : "foo" | "bar" | "baz" | string +>"foo" : string + +var y: T = "bar"; +>y : string | "foo" | "bar" | "baz" +>T : string | "foo" | "bar" | "baz" +>"bar" : string + +if (x === "foo") { +>x === "foo" : boolean +>x : "foo" | "bar" | "baz" | string +>"foo" : string + + let a = x; +>a : "foo" | "bar" | "baz" | string +>x : "foo" | "bar" | "baz" | string +} +else if (x !== "bar") { +>x !== "bar" : boolean +>x : "foo" | "bar" | "baz" | string +>"bar" : string + + let b = x || y; +>b : string +>x || y : string +>x : "foo" | "bar" | "baz" | string +>y : string | "foo" | "bar" | "baz" +} +else { + let c = x; +>c : "foo" | "bar" | "baz" | string +>x : "foo" | "bar" | "baz" | string + + let d = y; +>d : string | "foo" | "bar" | "baz" +>y : string | "foo" | "bar" | "baz" + + let e: (typeof x) | (typeof y) = c || d; +>e : "foo" | "bar" | "baz" | string +>x : "foo" | "bar" | "baz" | string +>y : string | "foo" | "bar" | "baz" +>c || d : string +>c : "foo" | "bar" | "baz" | string +>d : string | "foo" | "bar" | "baz" +} + +x = y; +>x = y : string | "foo" | "bar" | "baz" +>x : "foo" | "bar" | "baz" | string +>y : string | "foo" | "bar" | "baz" + +y = x; +>y = x : "foo" | "bar" | "baz" | string +>y : string | "foo" | "bar" | "baz" +>x : "foo" | "bar" | "baz" | string + diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.errors.txt b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.errors.txt index 1595c625322..8ff377b2e72 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.errors.txt @@ -1,43 +1,27 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(2,18): error TS4081: Exported type alias 'T' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(2,19): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(2,19): 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/stringLiteralTypesInUnionTypes03.ts(2,27): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(4,7): error TS4025: Exported variable 'x' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(4,8): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(4,8): 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/stringLiteralTypesInUnionTypes03.ts(4,16): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(4,24): error TS2304: Cannot find name 'number'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(5,5): error TS2322: Type 'string' is not assignable to type 'number | "foo" | "bar"'. + Type 'string' is not assignable to type '"bar"'. +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 (9 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts (3 errors) ==== type T = number | "foo" | "bar"; - -!!! error TS4081: Exported type alias 'T' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. - ~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. var x: "foo" | "bar" | number; - -!!! error TS4025: Exported variable 'x' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. - ~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~~ -!!! error TS2304: Cannot find name 'number'. var y: T = "bar"; + ~ +!!! error TS2322: Type 'string' is not assignable to type 'number | "foo" | "bar"'. +!!! error TS2322: Type 'string' is not assignable to type '"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 { diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.js b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.js index 7705848be2b..f6728e0b2fb 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.js +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.js @@ -21,8 +21,7 @@ x = y; y = x; //// [stringLiteralTypesInUnionTypes03.js] -"foo" | "bar"; -var x = "foo" | "bar" | number; +var x; var y = "bar"; if (x === "foo") { var a = x; @@ -37,3 +36,9 @@ else { } x = y; y = x; + + +//// [stringLiteralTypesInUnionTypes03.d.ts] +declare type T = number | "foo" | "bar"; +declare var x: "foo" | "bar" | number; +declare var y: T; diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.errors.txt b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.errors.txt index 66d3e215237..77cb9c09531 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.errors.txt @@ -1,23 +1,21 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes04.ts(2,9): error TS4081: Exported type alias 'T' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes04.ts(2,10): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes04.ts(2,10): 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/stringLiteralTypesInUnionTypes04.ts(2,15): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes04.ts(4,5): error TS2322: Type 'string' is not assignable to type '"" | "foo"'. + Type 'string' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes04.ts(5,5): error TS2322: Type 'string' is not assignable to type '"" | "foo"'. + Type 'string' is not assignable to type '"foo"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes04.ts (4 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes04.ts (2 errors) ==== type T = "" | "foo"; - -!!! error TS4081: Exported type alias 'T' has or is using private name ''. - ~~ -!!! error TS1110: Type expected. - ~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. let x: T = ""; + ~ +!!! error TS2322: Type 'string' is not assignable to type '"" | "foo"'. +!!! error TS2322: Type 'string' is not assignable to type '"foo"'. let y: T = "foo"; + ~ +!!! error TS2322: Type 'string' is not assignable to type '"" | "foo"'. +!!! error TS2322: Type 'string' is not assignable to type '"foo"'. if (x === "") { let a = x; diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.js b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.js index 5817d16ec8f..dc6cf51ad1e 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.js +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.js @@ -38,7 +38,6 @@ if (!!!x) { } //// [stringLiteralTypesInUnionTypes04.js] -"" | "foo"; var x = ""; var y = "foo"; if (x === "") { @@ -65,3 +64,9 @@ if (!!x) { if (!!!x) { var h = x; } + + +//// [stringLiteralTypesInUnionTypes04.d.ts] +declare type T = "" | "foo"; +declare let x: T; +declare let y: T; diff --git a/tests/baselines/reference/stringLiteralTypesInVariableDeclarations01.errors.txt b/tests/baselines/reference/stringLiteralTypesInVariableDeclarations01.errors.txt index 14233db44cd..3dd2adbbce0 100644 --- a/tests/baselines/reference/stringLiteralTypesInVariableDeclarations01.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesInVariableDeclarations01.errors.txt @@ -1,81 +1,54 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(2,7): error TS4025: Exported variable 'a' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(2,8): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(3,7): error TS4025: Exported variable 'b' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(3,8): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(4,7): error TS4025: Exported variable 'c' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(4,8): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(5,9): error TS4025: Exported variable 'd' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(5,10): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(11,7): error TS4025: Exported variable 'e' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(11,8): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(11,8): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(12,7): error TS4025: Exported variable 'f' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(12,8): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(12,8): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(13,7): error TS4025: Exported variable 'g' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(13,8): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(13,8): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(14,9): error TS4025: Exported variable 'h' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(14,10): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(14,10): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(5,7): error TS1155: 'const' declarations must be initialized +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(7,1): error TS2322: Type 'string' is not assignable to type '""'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(8,1): error TS2322: Type 'string' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(9,1): error TS2322: Type 'string' is not assignable to type '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(11,5): error TS2322: Type 'string' is not assignable to type '""'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(12,5): error TS2322: Type 'string' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(13,5): error TS2322: Type 'string' is not assignable to type '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(14,7): error TS2322: Type 'string' is not assignable to type '"baz"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(16,1): error TS2322: Type 'string' is not assignable to type '""'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(17,1): error TS2322: Type 'string' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts(18,1): error TS2322: Type 'string' is not assignable to type '"bar"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts (20 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts (11 errors) ==== let a: ""; - -!!! error TS4025: Exported variable 'a' has or is using private name ''. - ~~ -!!! error TS1110: Type expected. var b: "foo"; - -!!! error TS4025: Exported variable 'b' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. let c: "bar"; - -!!! error TS4025: Exported variable 'c' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. const d: "baz"; - -!!! error TS4025: Exported variable 'd' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. + ~ +!!! error TS1155: 'const' declarations must be initialized a = ""; + ~ +!!! error TS2322: Type 'string' is not assignable to type '""'. b = "foo"; + ~ +!!! error TS2322: Type 'string' is not assignable to type '"foo"'. c = "bar"; + ~ +!!! error TS2322: Type 'string' is not assignable to type '"bar"'. let e: "" = ""; - -!!! error TS4025: Exported variable 'e' has or is using private name ''. - ~~ -!!! error TS1110: Type expected. - ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2322: Type 'string' is not assignable to type '""'. var f: "foo" = "foo"; - -!!! error TS4025: Exported variable 'f' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. - ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2322: Type 'string' is not assignable to type '"foo"'. let g: "bar" = "bar"; - -!!! error TS4025: Exported variable 'g' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. - ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2322: Type 'string' is not assignable to type '"bar"'. const h: "baz" = "baz"; - -!!! error TS4025: Exported variable 'h' has or is using private name ''. - ~~~~~ -!!! error TS1110: Type expected. - ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2322: Type 'string' is not assignable to type '"baz"'. e = ""; + ~ +!!! error TS2322: Type 'string' is not assignable to type '""'. f = "foo"; - g = "bar"; \ No newline at end of file + ~ +!!! error TS2322: Type 'string' is not assignable to type '"foo"'. + g = "bar"; + ~ +!!! error TS2322: Type 'string' is not assignable to type '"bar"'. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesInVariableDeclarations01.js b/tests/baselines/reference/stringLiteralTypesInVariableDeclarations01.js index 4aae2a2438a..15a4ca5d580 100644 --- a/tests/baselines/reference/stringLiteralTypesInVariableDeclarations01.js +++ b/tests/baselines/reference/stringLiteralTypesInVariableDeclarations01.js @@ -19,17 +19,28 @@ f = "foo"; g = "bar"; //// [stringLiteralTypesInVariableDeclarations01.js] -var a = ""; -var b = "foo"; -var c = "bar"; -var d = "baz"; +var a; +var b; +var c; +var d; a = ""; b = "foo"; c = "bar"; -var e = "" = ""; -var f = "foo" = "foo"; -var g = "bar" = "bar"; -var h = "baz" = "baz"; +var e = ""; +var f = "foo"; +var g = "bar"; +var h = "baz"; e = ""; f = "foo"; g = "bar"; + + +//// [stringLiteralTypesInVariableDeclarations01.d.ts] +declare let a: ""; +declare var b: "foo"; +declare let c: "bar"; +declare const d: "baz"; +declare let e: ""; +declare var f: "foo"; +declare let g: "bar"; +declare const h: "baz"; diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.errors.txt b/tests/baselines/reference/stringLiteralTypesOverloads01.errors.txt index e41de718dfa..378857dc277 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads01.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesOverloads01.errors.txt @@ -1,86 +1,20 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(2,21): error TS4081: Exported type alias 'PrimitiveName' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(2,22): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(2,22): 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/stringLiteralTypesOverloads01.ts(2,33): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(2,44): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(4,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(5,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(6,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(7,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(7,28): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(7,41): error TS1005: '=' expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(8,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(8,28): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(8,41): error TS1005: '=' expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(9,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(9,28): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(9,40): error TS1005: '=' expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(10,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(10,28): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(10,40): error TS1005: '=' expected. tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(11,10): error TS2354: No best common type exists among return expressions. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(32,14): error TS4025: Exported variable 'string' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(32,15): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(32,15): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(33,14): error TS4025: Exported variable 'number' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(33,15): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(33,15): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(34,15): error TS4025: Exported variable 'boolean' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(34,16): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(34,16): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(32,7): error TS2322: Type 'string' is not assignable to type '"string"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(33,7): error TS2322: Type 'string' is not assignable to type ''number''. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(34,7): error TS2322: Type 'string' is not assignable to type '"boolean"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts (30 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts (4 errors) ==== type PrimitiveName = 'string' | 'number' | 'boolean'; - -!!! error TS4081: Exported type alias 'PrimitiveName' has or is using private name ''. - ~~~~~~~~ -!!! error TS1110: Type expected. - ~~~~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. function getFalsyPrimitive(x: "string"): string; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function getFalsyPrimitive(x: "number"): number; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function getFalsyPrimitive(x: "boolean"): boolean; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - ~ -!!! error TS1005: '=' expected. function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - ~ -!!! error TS1005: '=' expected. function getFalsyPrimitive(x: "number" | "string"): number | string; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - ~ -!!! error TS1005: '=' expected. function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - ~ -!!! error TS1005: '=' expected. function getFalsyPrimitive(x: PrimitiveName) { ~~~~~~~~~~~~~~~~~ !!! error TS2354: No best common type exists among return expressions. @@ -105,26 +39,14 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(34, } const string: "string" = "string" - -!!! error TS4025: Exported variable 'string' has or is using private name ''. - ~~~~~~~~ -!!! error TS1110: Type expected. - ~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type '"string"'. const number: "number" = "number" - -!!! error TS4025: Exported variable 'number' has or is using private name ''. - ~~~~~~~~ -!!! error TS1110: Type expected. - ~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type ''number''. const boolean: "boolean" = "boolean" - -!!! error TS4025: Exported variable 'boolean' has or is using private name ''. - ~~~~~~~~~ -!!! error TS1110: Type expected. - ~~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type '"boolean"'. const stringOrNumber = string || number; const stringOrBoolean = string || boolean; diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.js b/tests/baselines/reference/stringLiteralTypesOverloads01.js index a001f02c9c9..23483776a9b 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads01.js +++ b/tests/baselines/reference/stringLiteralTypesOverloads01.js @@ -54,7 +54,6 @@ namespace Consts2 { //// [stringLiteralTypesOverloads01.js] -'string' | 'number' | 'boolean'; function getFalsyPrimitive(x) { if (x === "string") { return ""; @@ -74,9 +73,9 @@ var Consts1; var ZERO = getFalsyPrimitive('number'); var FALSE = getFalsyPrimitive("boolean"); })(Consts1 || (Consts1 = {})); -var string = "string" = "string"; -var number = "number" = "number"; -var boolean = "boolean" = "boolean"; +var string = "string"; +var number = "number"; +var boolean = "boolean"; var stringOrNumber = string || number; var stringOrBoolean = string || boolean; var booleanOrNumber = number || boolean; @@ -91,3 +90,25 @@ var Consts2; var c = getFalsyPrimitive(booleanOrNumber); var d = getFalsyPrimitive(stringOrBooleanOrNumber); })(Consts2 || (Consts2 = {})); + + +//// [stringLiteralTypesOverloads01.d.ts] +declare type PrimitiveName = 'string' | 'number' | 'boolean'; +declare function getFalsyPrimitive(x: "string"): string; +declare function getFalsyPrimitive(x: "number"): number; +declare function getFalsyPrimitive(x: "boolean"): boolean; +declare function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; +declare function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; +declare function getFalsyPrimitive(x: "number" | "string"): number | string; +declare function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; +declare namespace Consts1 { +} +declare const string: "string"; +declare const number: "number"; +declare const boolean: "boolean"; +declare const stringOrNumber: "string" | 'number'; +declare const stringOrBoolean: "string" | "boolean"; +declare const booleanOrNumber: 'number' | "boolean"; +declare const stringOrBooleanOrNumber: "string" | "boolean" | 'number'; +declare namespace Consts2 { +} diff --git a/tests/baselines/reference/stringLiteralTypesOverloads02.errors.txt b/tests/baselines/reference/stringLiteralTypesOverloads02.errors.txt index ff1e212c071..ae9fb9ce4f6 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads02.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesOverloads02.errors.txt @@ -1,69 +1,18 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(2,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(3,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(4,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(5,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(5,28): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(5,41): error TS1005: '=' expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(6,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(6,28): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(6,41): error TS1005: '=' expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(7,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(7,28): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(7,40): error TS1005: '=' expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(8,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(8,28): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(8,40): error TS1005: '=' expected. 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(30,14): error TS4025: Exported variable 'string' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(30,15): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(30,15): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(31,14): error TS4025: Exported variable 'number' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(31,15): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(31,15): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(32,15): error TS4025: Exported variable 'boolean' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(32,16): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(32,16): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(30,7): error TS2322: Type 'string' is not assignable to type '"string"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(31,7): error TS2322: Type 'string' is not assignable to type '"number"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(32,7): error TS2322: Type 'string' is not assignable to type '"boolean"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts (25 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts (4 errors) ==== function getFalsyPrimitive(x: "string"): string; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function getFalsyPrimitive(x: "number"): number; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function getFalsyPrimitive(x: "boolean"): boolean; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - ~ -!!! error TS1005: '=' expected. function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - ~ -!!! error TS1005: '=' expected. function getFalsyPrimitive(x: "number" | "string"): number | string; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - ~ -!!! error TS1005: '=' expected. function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; - ~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - ~ -!!! error TS1005: '=' expected. function getFalsyPrimitive(x: string) { ~~~~~~~~~~~~~~~~~ !!! error TS2354: No best common type exists among return expressions. @@ -88,26 +37,14 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads02.ts(32, } const string: "string" = "string" - -!!! error TS4025: Exported variable 'string' has or is using private name ''. - ~~~~~~~~ -!!! error TS1110: Type expected. - ~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type '"string"'. const number: "number" = "number" - -!!! error TS4025: Exported variable 'number' has or is using private name ''. - ~~~~~~~~ -!!! error TS1110: Type expected. - ~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type '"number"'. const boolean: "boolean" = "boolean" - -!!! error TS4025: Exported variable 'boolean' has or is using private name ''. - ~~~~~~~~~ -!!! error TS1110: Type expected. - ~~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type '"boolean"'. const stringOrNumber = string || number; const stringOrBoolean = string || boolean; diff --git a/tests/baselines/reference/stringLiteralTypesOverloads02.js b/tests/baselines/reference/stringLiteralTypesOverloads02.js index ae38acebb95..3c53f9380a8 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads02.js +++ b/tests/baselines/reference/stringLiteralTypesOverloads02.js @@ -71,9 +71,9 @@ var Consts1; var ZERO = getFalsyPrimitive('number'); var FALSE = getFalsyPrimitive("boolean"); })(Consts1 || (Consts1 = {})); -var string = "string" = "string"; -var number = "number" = "number"; -var boolean = "boolean" = "boolean"; +var string = "string"; +var number = "number"; +var boolean = "boolean"; var stringOrNumber = string || number; var stringOrBoolean = string || boolean; var booleanOrNumber = number || boolean; @@ -88,3 +88,24 @@ var Consts2; var c = getFalsyPrimitive(booleanOrNumber); var d = getFalsyPrimitive(stringOrBooleanOrNumber); })(Consts2 || (Consts2 = {})); + + +//// [stringLiteralTypesOverloads02.d.ts] +declare function getFalsyPrimitive(x: "string"): string; +declare function getFalsyPrimitive(x: "number"): number; +declare function getFalsyPrimitive(x: "boolean"): boolean; +declare function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; +declare function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; +declare function getFalsyPrimitive(x: "number" | "string"): number | string; +declare function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; +declare namespace Consts1 { +} +declare const string: "string"; +declare const number: "number"; +declare const boolean: "boolean"; +declare const stringOrNumber: "string" | "number"; +declare const stringOrBoolean: "string" | "boolean"; +declare const booleanOrNumber: "number" | "boolean"; +declare const stringOrBooleanOrNumber: "string" | "boolean" | "number"; +declare namespace Consts2 { +} diff --git a/tests/baselines/reference/stringLiteralTypesTypePredicates01.errors.txt b/tests/baselines/reference/stringLiteralTypesTypePredicates01.errors.txt index a4cc525cdd2..3e412a6c770 100644 --- a/tests/baselines/reference/stringLiteralTypesTypePredicates01.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesTypePredicates01.errors.txt @@ -1,46 +1,27 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(2,12): error TS4081: Exported type alias 'Kind' has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(2,13): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(2,13): 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/stringLiteralTypesTypePredicates01.ts(2,19): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(4,10): error TS2391: Function implementation is missing or not immediately following the declaration. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(4,46): error TS4060: Return type of exported function has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(4,47): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(5,10): error TS2391: Function implementation is missing or not immediately following the declaration. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(5,46): error TS4060: Return type of exported function has or is using private name ''. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(5,47): error TS1110: Type expected. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(4,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(5,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(10,5): error TS2322: Type 'string' is not assignable to type '"A" | "B"'. + Type 'string' is not assignable to type '"B"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts (10 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts (3 errors) ==== type Kind = "A" | "B" - -!!! error TS4081: Exported type alias 'Kind' has or is using private name ''. - ~~~ -!!! error TS1110: Type expected. - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. function kindIs(kind: Kind, is: "A"): kind is "A"; ~~~~~~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. - -!!! error TS4060: Return type of exported function has or is using private name ''. - ~~~ -!!! error TS1110: Type expected. +!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function kindIs(kind: Kind, is: "B"): kind is "B"; ~~~~~~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. - -!!! error TS4060: Return type of exported function has or is using private name ''. - ~~~ -!!! error TS1110: Type expected. +!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function kindIs(kind: Kind, is: Kind): boolean { return kind === is; } var x: Kind = "A"; + ~ +!!! error TS2322: Type 'string' is not assignable to type '"A" | "B"'. +!!! error TS2322: Type 'string' is not assignable to type '"B"'. if (kindIs(x, "A")) { let a = x; diff --git a/tests/baselines/reference/stringLiteralTypesTypePredicates01.js b/tests/baselines/reference/stringLiteralTypesTypePredicates01.js index 791caed9b31..fd4129d272d 100644 --- a/tests/baselines/reference/stringLiteralTypesTypePredicates01.js +++ b/tests/baselines/reference/stringLiteralTypesTypePredicates01.js @@ -25,9 +25,6 @@ else { } //// [stringLiteralTypesTypePredicates01.js] -"A" | "B"; -"A"; -"B"; function kindIs(kind, is) { return kind === is; } @@ -44,3 +41,10 @@ if (!kindIs(x, "B")) { else { var d = x; } + + +//// [stringLiteralTypesTypePredicates01.d.ts] +declare type Kind = "A" | "B"; +declare function kindIs(kind: Kind, is: "A"): kind is "A"; +declare function kindIs(kind: Kind, is: "B"): kind is "B"; +declare var x: Kind; diff --git a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt index 626d0e3d6f4..f6421445ae1 100644 --- a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt +++ b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt @@ -1,23 +1,19 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(4,18): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(4,48): error TS4060: Return type of exported function has or is using private name ''. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(4,49): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(5,18): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(5,39): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(5,52): error TS1005: '=' expected. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(5,63): error TS4060: Return type of exported function has or is using private name ''. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(5,64): error TS1110: Type expected. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(5,64): 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/typeArgumentsWithStringLiteralTypes01.ts(5,74): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(37,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(38,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(39,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(40,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(41,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(44,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(45,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(46,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(47,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(48,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(44,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. + Type 'string' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(45,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. + Type 'string' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(46,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. + Type 'string' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(47,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. + Type 'string' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(48,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. + Type 'string' is not assignable to type '"World"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(54,20): error TS2365: Operator '<' cannot be applied to types '(x: T, y: T) => T' and 'string'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(54,20): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(55,20): error TS2365: Operator '<' cannot be applied to types '(x: T, y: T) => T' and 'string'. @@ -38,11 +34,16 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0 tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(70,25): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(71,25): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(72,25): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(75,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(76,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(77,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(78,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(79,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(75,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. + Type 'boolean' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(76,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. + Type 'boolean' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(77,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. + Type 'boolean' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(78,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. + Type 'boolean' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(79,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. + Type 'boolean' is not assignable to type '"World"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(86,20): error TS2365: Operator '<' cannot be applied to types '(x: T, y: U) => T | U' and 'string'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(86,34): error TS1134: Variable declaration expected. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(87,20): error TS2365: Operator '<' cannot be applied to types '(x: T, y: U) => T | U' and 'string'. @@ -63,39 +64,26 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0 tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(102,25): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(103,25): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(104,25): error TS2345: Argument of type 'number' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(107,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(108,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(109,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(110,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(111,30): error TS2345: Argument of type 'number' is not assignable to parameter of type '"Hello"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(107,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. + Type 'boolean' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(108,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. + Type 'boolean' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(109,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. + Type 'boolean' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(110,30): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. + Type 'boolean' is not assignable to type '"World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(111,30): error TS2345: Argument of type 'number' is not assignable to parameter of type '"Hello" | "World"'. + Type 'number' is not assignable to type '"World"'. -==== tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts (70 errors) ==== +==== tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts (61 errors) ==== declare function randBool(): boolean; declare function takeReturnString(str: string): string; declare function takeReturnHello(str: "Hello"): "Hello"; ~~~~~~~~~~~~~~~ !!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - -!!! error TS4060: Return type of exported function has or is using private name ''. - ~~~~~~~ -!!! error TS1110: Type expected. declare function takeReturnHelloWorld(str: "Hello" | "World"): "Hello" | "World"; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - ~ -!!! error TS1005: '=' expected. - -!!! error TS4060: Return type of exported function has or is using private name ''. - ~~~~~~~ -!!! error TS1110: Type expected. - ~~~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - ~~~~~~~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. function fun1(x: T, y: T) { return randBool() ? x : y; @@ -146,19 +134,24 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0 // Passing these as arguments should cause an error. a = takeReturnHelloWorld(a); ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'string' is not assignable to type '"World"'. b = takeReturnHelloWorld(b); ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'string' is not assignable to type '"World"'. c = takeReturnHelloWorld(c); ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'string' is not assignable to type '"World"'. d = takeReturnHelloWorld(d); ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'string' is not assignable to type '"World"'. e = takeReturnHelloWorld(e); ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'string' is not assignable to type '"World"'. } namespace n2 { @@ -227,19 +220,24 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0 // Assignment from the returned value should cause an error. a = takeReturnHelloWorld(a); ~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'boolean' is not assignable to type '"World"'. b = takeReturnHelloWorld(b); ~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'boolean' is not assignable to type '"World"'. c = takeReturnHelloWorld(c); ~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'boolean' is not assignable to type '"World"'. d = takeReturnHelloWorld(d); ~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'boolean' is not assignable to type '"World"'. e = takeReturnHelloWorld(e); ~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'boolean' is not assignable to type '"World"'. } @@ -309,17 +307,22 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0 // Both should be valid. a = takeReturnHelloWorld(a); ~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'boolean' is not assignable to type '"World"'. b = takeReturnHelloWorld(b); ~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'boolean' is not assignable to type '"World"'. c = takeReturnHelloWorld(c); ~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'boolean' is not assignable to type '"World"'. d = takeReturnHelloWorld(d); ~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'boolean' is not assignable to type '"World"'. e = takeReturnHelloWorld(e); ~ -!!! error TS2345: Argument of type 'number' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type '"Hello" | "World"'. +!!! error TS2345: Type 'number' is not assignable to type '"World"'. } \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js index 15c7cf5ef2d..e6e2b695a3b 100644 --- a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js +++ b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js @@ -113,8 +113,6 @@ namespace n3 { } //// [typeArgumentsWithStringLiteralTypes01.js] -"Hello"; -"Hello" | "World"; function fun1(x, y) { return randBool() ? x : y; } @@ -219,3 +217,34 @@ var n3; n3.d = takeReturnHelloWorld(n3.d); n3.e = takeReturnHelloWorld(n3.e); })(n3 || (n3 = {})); + + +//// [typeArgumentsWithStringLiteralTypes01.d.ts] +declare function randBool(): boolean; +declare function takeReturnString(str: string): string; +declare function takeReturnHello(str: "Hello"): "Hello"; +declare function takeReturnHelloWorld(str: "Hello" | "World"): "Hello" | "World"; +declare function fun1(x: T, y: T): T; +declare function fun2(x: T, y: U): T | U; +declare function fun3(...args: T[]): T; +declare namespace n1 { + let a: string; + let b: string; + let c: string; + let d: string; + let e: string; +} +declare namespace n2 { + let a: boolean; + let b: boolean; + let c: boolean; + let d: boolean; + let e: boolean; +} +declare namespace n3 { + let a: boolean; + let b: boolean; + let c: boolean; + let d: boolean; + let e: number; +}