Accepted baselines.

This commit is contained in:
Daniel Rosenwasser
2015-10-01 15:54:16 -07:00
parent 911e907306
commit f04cc39a68
20 changed files with 1783 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
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; }'.
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts (13 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;
}
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;
}
function hasKind(entity: Entity, kind: "A"): entity is A;
~~~~~~~
!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
function hasKind(entity: Entity, kind: "B"): entity is B;
~~~~~~~
!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
function hasKind(entity: Entity, kind: Kind): entity is Entity;
~~~~~~~
!!! error TS2394: Overload signature is not compatible with function implementation.
function hasKind(entity: Entity, kind: Kind): boolean {
return kind === is;
~~
!!! error TS2304: Cannot find name 'is'.
}
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; }'.
kind: "A",
a: 100,
}
if (hasKind(x, "A")) {
let a = x;
}
else {
let b = x;
}
if (!hasKind(x, "B")) {
let c = x;
}
else {
let d = x;
}

View File

@@ -0,0 +1,65 @@
//// [stringLiteralTypesAsTags01.ts]
type Kind = "A" | "B"
interface Entity {
kind: Kind;
}
interface A extends Entity {
kind: "A";
a: number;
}
interface B extends Entity {
kind: "B";
b: string;
}
function hasKind(entity: Entity, kind: "A"): entity is A;
function hasKind(entity: Entity, kind: "B"): entity is B;
function hasKind(entity: Entity, kind: Kind): entity is Entity;
function hasKind(entity: Entity, kind: Kind): boolean {
return kind === is;
}
let x: A = {
kind: "A",
a: 100,
}
if (hasKind(x, "A")) {
let a = x;
}
else {
let b = x;
}
if (!hasKind(x, "B")) {
let c = x;
}
else {
let d = x;
}
//// [stringLiteralTypesAsTags01.js]
"A" | "B";
function hasKind(entity, kind) {
return kind === is;
}
var x = {
kind: "A",
a: 100
};
if (hasKind(x, "A")) {
var a = x;
}
else {
var b = x;
}
if (!hasKind(x, "B")) {
var c = x;
}
else {
var d = x;
}

View File

@@ -0,0 +1,59 @@
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 (12 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.
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;

View File

@@ -0,0 +1,40 @@
//// [stringLiteralTypesInUnionTypes01.ts]
type T = "foo" | "bar" | "baz";
var x: "foo" | "bar" | "baz" = "foo";
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;
//// [stringLiteralTypesInUnionTypes01.js]
"foo" | "bar" | "baz";
var x = "foo" | "bar" | "baz";
"foo";
var y = "bar";
if (x === "foo") {
var a = x;
}
else if (x !== "bar") {
var b = x || y;
}
else {
var c = x;
var d = y;
var e = c || d;
}
x = y;
y = x;

View File

@@ -0,0 +1,62 @@
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;

View File

@@ -0,0 +1,40 @@
//// [stringLiteralTypesInUnionTypes02.ts]
type T = string | "foo" | "bar" | "baz";
var x: "foo" | "bar" | "baz" | string = "foo";
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;
//// [stringLiteralTypesInUnionTypes02.js]
"foo" | "bar" | "baz";
var x = "foo" | "bar" | "baz" | string;
"foo";
var y = "bar";
if (x === "foo") {
var a = x;
}
else if (x !== "bar") {
var b = x || y;
}
else {
var c = x;
var d = y;
var e = c || d;
}
x = y;
y = x;

View File

@@ -0,0 +1,50 @@
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 (9 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";
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;

View File

@@ -0,0 +1,39 @@
//// [stringLiteralTypesInUnionTypes03.ts]
type T = number | "foo" | "bar";
var x: "foo" | "bar" | number;
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;
//// [stringLiteralTypesInUnionTypes03.js]
"foo" | "bar";
var x = "foo" | "bar" | number;
var y = "bar";
if (x === "foo") {
var a = x;
}
else if (x !== "bar") {
var b = x || y;
}
else {
var c = x;
var d = y;
var e = c || d;
}
x = y;
y = x;

View File

@@ -0,0 +1,52 @@
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 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 = "";
let y: T = "foo";
if (x === "") {
let a = x;
}
if (x !== "") {
let b = x;
}
if (x == "") {
let c = x;
}
if (x != "") {
let d = x;
}
if (x) {
let e = x;
}
if (!x) {
let f = x;
}
if (!!x) {
let g = x;
}
if (!!!x) {
let h = x;
}

View File

@@ -0,0 +1,67 @@
//// [stringLiteralTypesInUnionTypes04.ts]
type T = "" | "foo";
let x: T = "";
let y: T = "foo";
if (x === "") {
let a = x;
}
if (x !== "") {
let b = x;
}
if (x == "") {
let c = x;
}
if (x != "") {
let d = x;
}
if (x) {
let e = x;
}
if (!x) {
let f = x;
}
if (!!x) {
let g = x;
}
if (!!!x) {
let h = x;
}
//// [stringLiteralTypesInUnionTypes04.js]
"" | "foo";
var x = "";
var y = "foo";
if (x === "") {
var a = x;
}
if (x !== "") {
var b = x;
}
if (x == "") {
var c = x;
}
if (x != "") {
var d = x;
}
if (x) {
var e = x;
}
if (!x) {
var f = x;
}
if (!!x) {
var g = x;
}
if (!!!x) {
var h = x;
}

View File

@@ -0,0 +1,81 @@
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 (20 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.
a = "";
b = "foo";
c = "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.
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.
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.
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.
e = "";
f = "foo";
g = "bar";

View File

@@ -0,0 +1,35 @@
//// [stringLiteralTypesInVariableDeclarations01.ts]
let a: "";
var b: "foo";
let c: "bar";
const d: "baz";
a = "";
b = "foo";
c = "bar";
let e: "" = "";
var f: "foo" = "foo";
let g: "bar" = "bar";
const h: "baz" = "baz";
e = "";
f = "foo";
g = "bar";
//// [stringLiteralTypesInVariableDeclarations01.js]
var a = "";
var b = "foo";
var c = "bar";
var d = "baz";
a = "";
b = "foo";
c = "bar";
var e = "" = "";
var f = "foo" = "foo";
var g = "bar" = "bar";
var h = "baz" = "baz";
e = "";
f = "foo";
g = "bar";

View File

@@ -0,0 +1,146 @@
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 (30 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.
if (x === "string") {
return "";
}
if (x === "number") {
return 0;
}
if (x === "boolean") {
return false;
}
// Should be unreachable.
throw "Invalid value";
}
namespace Consts1 {
const EMPTY_STRING = getFalsyPrimitive("string");
const ZERO = getFalsyPrimitive('number');
const FALSE = getFalsyPrimitive("boolean");
}
const string: "string" = "string"
!!! error TS4025: Exported variable 'string' has or is using private name ''.
~~~~~~~~
!!! error TS1110: Type expected.
~~~~~~~~
!!! error TS2364: Invalid left-hand side of assignment expression.
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.
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.
const stringOrNumber = string || number;
const stringOrBoolean = string || boolean;
const booleanOrNumber = number || boolean;
const stringOrBooleanOrNumber = stringOrBoolean || number;
namespace Consts2 {
const EMPTY_STRING = getFalsyPrimitive(string);
const ZERO = getFalsyPrimitive(number);
const FALSE = getFalsyPrimitive(boolean);
const a = getFalsyPrimitive(stringOrNumber);
const b = getFalsyPrimitive(stringOrBoolean);
const c = getFalsyPrimitive(booleanOrNumber);
const d = getFalsyPrimitive(stringOrBooleanOrNumber);
}

View File

@@ -0,0 +1,93 @@
//// [stringLiteralTypesOverloads01.ts]
type PrimitiveName = 'string' | 'number' | 'boolean';
function getFalsyPrimitive(x: "string"): string;
function getFalsyPrimitive(x: "number"): number;
function getFalsyPrimitive(x: "boolean"): boolean;
function getFalsyPrimitive(x: "boolean" | "string"): boolean | string;
function getFalsyPrimitive(x: "boolean" | "number"): boolean | number;
function getFalsyPrimitive(x: "number" | "string"): number | string;
function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean;
function getFalsyPrimitive(x: PrimitiveName) {
if (x === "string") {
return "";
}
if (x === "number") {
return 0;
}
if (x === "boolean") {
return false;
}
// Should be unreachable.
throw "Invalid value";
}
namespace Consts1 {
const EMPTY_STRING = getFalsyPrimitive("string");
const ZERO = getFalsyPrimitive('number');
const FALSE = getFalsyPrimitive("boolean");
}
const string: "string" = "string"
const number: "number" = "number"
const boolean: "boolean" = "boolean"
const stringOrNumber = string || number;
const stringOrBoolean = string || boolean;
const booleanOrNumber = number || boolean;
const stringOrBooleanOrNumber = stringOrBoolean || number;
namespace Consts2 {
const EMPTY_STRING = getFalsyPrimitive(string);
const ZERO = getFalsyPrimitive(number);
const FALSE = getFalsyPrimitive(boolean);
const a = getFalsyPrimitive(stringOrNumber);
const b = getFalsyPrimitive(stringOrBoolean);
const c = getFalsyPrimitive(booleanOrNumber);
const d = getFalsyPrimitive(stringOrBooleanOrNumber);
}
//// [stringLiteralTypesOverloads01.js]
'string' | 'number' | 'boolean';
function getFalsyPrimitive(x) {
if (x === "string") {
return "";
}
if (x === "number") {
return 0;
}
if (x === "boolean") {
return false;
}
// Should be unreachable.
throw "Invalid value";
}
var Consts1;
(function (Consts1) {
var EMPTY_STRING = getFalsyPrimitive("string");
var ZERO = getFalsyPrimitive('number');
var FALSE = getFalsyPrimitive("boolean");
})(Consts1 || (Consts1 = {}));
var string = "string" = "string";
var number = "number" = "number";
var boolean = "boolean" = "boolean";
var stringOrNumber = string || number;
var stringOrBoolean = string || boolean;
var booleanOrNumber = number || boolean;
var stringOrBooleanOrNumber = stringOrBoolean || number;
var Consts2;
(function (Consts2) {
var EMPTY_STRING = getFalsyPrimitive(string);
var ZERO = getFalsyPrimitive(number);
var FALSE = getFalsyPrimitive(boolean);
var a = getFalsyPrimitive(stringOrNumber);
var b = getFalsyPrimitive(stringOrBoolean);
var c = getFalsyPrimitive(booleanOrNumber);
var d = getFalsyPrimitive(stringOrBooleanOrNumber);
})(Consts2 || (Consts2 = {}));

View File

@@ -0,0 +1,129 @@
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 (25 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.
if (x === "string") {
return "";
}
if (x === "number") {
return 0;
}
if (x === "boolean") {
return false;
}
// Should be unreachable.
throw "Invalid value";
}
namespace Consts1 {
const EMPTY_STRING = getFalsyPrimitive("string");
const ZERO = getFalsyPrimitive('number');
const FALSE = getFalsyPrimitive("boolean");
}
const string: "string" = "string"
!!! error TS4025: Exported variable 'string' has or is using private name ''.
~~~~~~~~
!!! error TS1110: Type expected.
~~~~~~~~
!!! error TS2364: Invalid left-hand side of assignment expression.
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.
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.
const stringOrNumber = string || number;
const stringOrBoolean = string || boolean;
const booleanOrNumber = number || boolean;
const stringOrBooleanOrNumber = stringOrBoolean || number;
namespace Consts2 {
const EMPTY_STRING = getFalsyPrimitive(string);
const ZERO = getFalsyPrimitive(number);
const FALSE = getFalsyPrimitive(boolean);
const a = getFalsyPrimitive(stringOrNumber);
const b = getFalsyPrimitive(stringOrBoolean);
const c = getFalsyPrimitive(booleanOrNumber);
const d = getFalsyPrimitive(stringOrBooleanOrNumber);
}

View File

@@ -0,0 +1,90 @@
//// [stringLiteralTypesOverloads02.ts]
function getFalsyPrimitive(x: "string"): string;
function getFalsyPrimitive(x: "number"): number;
function getFalsyPrimitive(x: "boolean"): boolean;
function getFalsyPrimitive(x: "boolean" | "string"): boolean | string;
function getFalsyPrimitive(x: "boolean" | "number"): boolean | number;
function getFalsyPrimitive(x: "number" | "string"): number | string;
function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean;
function getFalsyPrimitive(x: string) {
if (x === "string") {
return "";
}
if (x === "number") {
return 0;
}
if (x === "boolean") {
return false;
}
// Should be unreachable.
throw "Invalid value";
}
namespace Consts1 {
const EMPTY_STRING = getFalsyPrimitive("string");
const ZERO = getFalsyPrimitive('number');
const FALSE = getFalsyPrimitive("boolean");
}
const string: "string" = "string"
const number: "number" = "number"
const boolean: "boolean" = "boolean"
const stringOrNumber = string || number;
const stringOrBoolean = string || boolean;
const booleanOrNumber = number || boolean;
const stringOrBooleanOrNumber = stringOrBoolean || number;
namespace Consts2 {
const EMPTY_STRING = getFalsyPrimitive(string);
const ZERO = getFalsyPrimitive(number);
const FALSE = getFalsyPrimitive(boolean);
const a = getFalsyPrimitive(stringOrNumber);
const b = getFalsyPrimitive(stringOrBoolean);
const c = getFalsyPrimitive(booleanOrNumber);
const d = getFalsyPrimitive(stringOrBooleanOrNumber);
}
//// [stringLiteralTypesOverloads02.js]
function getFalsyPrimitive(x) {
if (x === "string") {
return "";
}
if (x === "number") {
return 0;
}
if (x === "boolean") {
return false;
}
// Should be unreachable.
throw "Invalid value";
}
var Consts1;
(function (Consts1) {
var EMPTY_STRING = getFalsyPrimitive("string");
var ZERO = getFalsyPrimitive('number');
var FALSE = getFalsyPrimitive("boolean");
})(Consts1 || (Consts1 = {}));
var string = "string" = "string";
var number = "number" = "number";
var boolean = "boolean" = "boolean";
var stringOrNumber = string || number;
var stringOrBoolean = string || boolean;
var booleanOrNumber = number || boolean;
var stringOrBooleanOrNumber = stringOrBoolean || number;
var Consts2;
(function (Consts2) {
var EMPTY_STRING = getFalsyPrimitive(string);
var ZERO = getFalsyPrimitive(number);
var FALSE = getFalsyPrimitive(boolean);
var a = getFalsyPrimitive(stringOrNumber);
var b = getFalsyPrimitive(stringOrBoolean);
var c = getFalsyPrimitive(booleanOrNumber);
var d = getFalsyPrimitive(stringOrBooleanOrNumber);
})(Consts2 || (Consts2 = {}));

View File

@@ -0,0 +1,57 @@
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 (10 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.
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.
function kindIs(kind: Kind, is: Kind): boolean {
return kind === is;
}
var x: Kind = "A";
if (kindIs(x, "A")) {
let a = x;
}
else {
let b = x;
}
if (!kindIs(x, "B")) {
let c = x;
}
else {
let d = x;
}

View File

@@ -0,0 +1,46 @@
//// [stringLiteralTypesTypePredicates01.ts]
type Kind = "A" | "B"
function kindIs(kind: Kind, is: "A"): kind is "A";
function kindIs(kind: Kind, is: "B"): kind is "B";
function kindIs(kind: Kind, is: Kind): boolean {
return kind === is;
}
var x: Kind = "A";
if (kindIs(x, "A")) {
let a = x;
}
else {
let b = x;
}
if (!kindIs(x, "B")) {
let c = x;
}
else {
let d = x;
}
//// [stringLiteralTypesTypePredicates01.js]
"A" | "B";
"A";
"B";
function kindIs(kind, is) {
return kind === is;
}
var x = "A";
if (kindIs(x, "A")) {
var a = x;
}
else {
var b = x;
}
if (!kindIs(x, "B")) {
var c = x;
}
else {
var d = x;
}

View File

@@ -0,0 +1,325 @@
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(54,20): error TS2365: Operator '<' cannot be applied to types '<T>(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 '<T>(x: T, y: T) => T' and 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(55,20): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(56,20): error TS2365: Operator '<' cannot be applied to types '<T, U>(x: T, y: U) => T | U' and 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(56,34): error TS1134: Variable declaration expected.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(57,20): error TS2365: Operator '<' cannot be applied to types '<T, U>(x: T, y: U) => T | U' and 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(57,34): error TS1134: Variable declaration expected.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(58,20): error TS2365: Operator '<' cannot be applied to types '<T>(...args: T[]) => T' and 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(58,20): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(61,26): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(62,26): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(63,26): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(64,26): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(65,26): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(68,25): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(69,25): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
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(86,20): error TS2365: Operator '<' cannot be applied to types '<T, U>(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 '<T, U>(x: T, y: U) => T | U' and 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(87,34): error TS1134: Variable declaration expected.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(88,20): error TS2365: Operator '<' cannot be applied to types '<T, U>(x: T, y: U) => T | U' and 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(88,34): error TS1134: Variable declaration expected.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(89,20): error TS2365: Operator '<' cannot be applied to types '<T, U>(x: T, y: U) => T | U' and 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(89,34): error TS1134: Variable declaration expected.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(90,20): error TS2365: Operator '<' cannot be applied to types '<T>(...args: T[]) => T' and 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(90,20): error TS2447: The '|' operator is not allowed for boolean types. Consider using '||' instead.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(93,26): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(94,26): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(95,26): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(96,26): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(97,26): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(100,25): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(101,25): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
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 (70 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<T>(x: T, y: T) {
return randBool() ? x : y;
}
function fun2<T, U>(x: T, y: U) {
return randBool() ? x : y;
}
function fun3<T>(...args: T[]): T {
return args[+randBool()];
}
namespace n1 {
// The following should all come back as strings.
// They should be assignable to/from something of a type 'string'.
// They should not be assignable to either "Hello" or "World".
export let a = fun1("Hello", "World");
export let b = fun1("Hello", "Hello");
export let c = fun2("Hello", "World");
export let d = fun2("Hello", "Hello");
export let e = fun3("Hello", "Hello", "World", "Foo");
// Should be valid
a = takeReturnString(a);
b = takeReturnString(b);
c = takeReturnString(c);
d = takeReturnString(d);
e = takeReturnString(e);
// Passing these as arguments should cause an error.
a = takeReturnHello(a);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
b = takeReturnHello(b);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
c = takeReturnHello(c);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
d = takeReturnHello(d);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
e = takeReturnHello(e);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
// 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"'.
b = takeReturnHelloWorld(b);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
c = takeReturnHelloWorld(c);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
d = takeReturnHelloWorld(d);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
e = takeReturnHelloWorld(e);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
}
namespace n2 {
// The following (regardless of errors) should come back typed
// as "Hello" (or "Hello" | "Hello").
export let a = fun1<"Hello">("Hello", "Hello");
~~~~~~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T>(x: T, y: T) => T' and 'string'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string'.
export let b = fun1<"Hello">("Hello", "World");
~~~~~~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T>(x: T, y: T) => T' and 'string'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string'.
export let c = fun2<"Hello", "Hello">("Hello", "Hello");
~~~~~~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T, U>(x: T, y: U) => T | U' and 'string'.
~~~~~~~
!!! error TS1134: Variable declaration expected.
export let d = fun2<"Hello", "Hello">("Hello", "World");
~~~~~~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T, U>(x: T, y: U) => T | U' and 'string'.
~~~~~~~
!!! error TS1134: Variable declaration expected.
export let e = fun3<"Hello">("Hello", "World");
~~~~~~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T>(...args: T[]) => T' and 'string'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string'.
// Assignment from the returned value should cause an error.
a = takeReturnString(a);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
b = takeReturnString(b);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
c = takeReturnString(c);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
d = takeReturnString(d);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
e = takeReturnString(e);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
// Should be valid
a = takeReturnHello(a);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
b = takeReturnHello(b);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
c = takeReturnHello(c);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
d = takeReturnHello(d);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
e = takeReturnHello(e);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
// 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"'.
b = takeReturnHelloWorld(b);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
c = takeReturnHelloWorld(c);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
d = takeReturnHelloWorld(d);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
e = takeReturnHelloWorld(e);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
}
namespace n3 {
// The following (regardless of errors) should come back typed
// as "Hello" | "World" (or "World" | "Hello").
export let a = fun2<"Hello", "World">("Hello", "World");
~~~~~~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T, U>(x: T, y: U) => T | U' and 'string'.
~~~~~~~
!!! error TS1134: Variable declaration expected.
export let b = fun2<"Hello", "World">("World", "Hello");
~~~~~~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T, U>(x: T, y: U) => T | U' and 'string'.
~~~~~~~
!!! error TS1134: Variable declaration expected.
export let c = fun2<"World", "Hello">("Hello", "Hello");
~~~~~~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T, U>(x: T, y: U) => T | U' and 'string'.
~~~~~~~
!!! error TS1134: Variable declaration expected.
export let d = fun2<"World", "Hello">("World", "World");
~~~~~~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T, U>(x: T, y: U) => T | U' and 'string'.
~~~~~~~
!!! error TS1134: Variable declaration expected.
export let e = fun3<"Hello" | "World">("Hello", "World");
~~~~~~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '<T>(...args: T[]) => T' and 'string'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2447: The '|' operator is not allowed for boolean types. Consider using '||' instead.
// Assignment from the returned value should cause an error.
a = takeReturnString(a);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
b = takeReturnString(b);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
c = takeReturnString(c);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
d = takeReturnString(d);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.
e = takeReturnString(e);
~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
// Passing these as arguments should cause an error.
a = takeReturnHello(a);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
b = takeReturnHello(b);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
c = takeReturnHello(c);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
d = takeReturnHello(d);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
e = takeReturnHello(e);
~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type '"Hello"'.
// Both should be valid.
a = takeReturnHelloWorld(a);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
b = takeReturnHelloWorld(b);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
c = takeReturnHelloWorld(c);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
d = takeReturnHelloWorld(d);
~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '"Hello"'.
e = takeReturnHelloWorld(e);
~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type '"Hello"'.
}

View File

@@ -0,0 +1,221 @@
//// [typeArgumentsWithStringLiteralTypes01.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";
function fun1<T>(x: T, y: T) {
return randBool() ? x : y;
}
function fun2<T, U>(x: T, y: U) {
return randBool() ? x : y;
}
function fun3<T>(...args: T[]): T {
return args[+randBool()];
}
namespace n1 {
// The following should all come back as strings.
// They should be assignable to/from something of a type 'string'.
// They should not be assignable to either "Hello" or "World".
export let a = fun1("Hello", "World");
export let b = fun1("Hello", "Hello");
export let c = fun2("Hello", "World");
export let d = fun2("Hello", "Hello");
export let e = fun3("Hello", "Hello", "World", "Foo");
// Should be valid
a = takeReturnString(a);
b = takeReturnString(b);
c = takeReturnString(c);
d = takeReturnString(d);
e = takeReturnString(e);
// Passing these as arguments should cause an error.
a = takeReturnHello(a);
b = takeReturnHello(b);
c = takeReturnHello(c);
d = takeReturnHello(d);
e = takeReturnHello(e);
// Passing these as arguments should cause an error.
a = takeReturnHelloWorld(a);
b = takeReturnHelloWorld(b);
c = takeReturnHelloWorld(c);
d = takeReturnHelloWorld(d);
e = takeReturnHelloWorld(e);
}
namespace n2 {
// The following (regardless of errors) should come back typed
// as "Hello" (or "Hello" | "Hello").
export let a = fun1<"Hello">("Hello", "Hello");
export let b = fun1<"Hello">("Hello", "World");
export let c = fun2<"Hello", "Hello">("Hello", "Hello");
export let d = fun2<"Hello", "Hello">("Hello", "World");
export let e = fun3<"Hello">("Hello", "World");
// Assignment from the returned value should cause an error.
a = takeReturnString(a);
b = takeReturnString(b);
c = takeReturnString(c);
d = takeReturnString(d);
e = takeReturnString(e);
// Should be valid
a = takeReturnHello(a);
b = takeReturnHello(b);
c = takeReturnHello(c);
d = takeReturnHello(d);
e = takeReturnHello(e);
// Assignment from the returned value should cause an error.
a = takeReturnHelloWorld(a);
b = takeReturnHelloWorld(b);
c = takeReturnHelloWorld(c);
d = takeReturnHelloWorld(d);
e = takeReturnHelloWorld(e);
}
namespace n3 {
// The following (regardless of errors) should come back typed
// as "Hello" | "World" (or "World" | "Hello").
export let a = fun2<"Hello", "World">("Hello", "World");
export let b = fun2<"Hello", "World">("World", "Hello");
export let c = fun2<"World", "Hello">("Hello", "Hello");
export let d = fun2<"World", "Hello">("World", "World");
export let e = fun3<"Hello" | "World">("Hello", "World");
// Assignment from the returned value should cause an error.
a = takeReturnString(a);
b = takeReturnString(b);
c = takeReturnString(c);
d = takeReturnString(d);
e = takeReturnString(e);
// Passing these as arguments should cause an error.
a = takeReturnHello(a);
b = takeReturnHello(b);
c = takeReturnHello(c);
d = takeReturnHello(d);
e = takeReturnHello(e);
// Both should be valid.
a = takeReturnHelloWorld(a);
b = takeReturnHelloWorld(b);
c = takeReturnHelloWorld(c);
d = takeReturnHelloWorld(d);
e = takeReturnHelloWorld(e);
}
//// [typeArgumentsWithStringLiteralTypes01.js]
"Hello";
"Hello" | "World";
function fun1(x, y) {
return randBool() ? x : y;
}
function fun2(x, y) {
return randBool() ? x : y;
}
function fun3() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
return args[+randBool()];
}
var n1;
(function (n1) {
// The following should all come back as strings.
// They should be assignable to/from something of a type 'string'.
// They should not be assignable to either "Hello" or "World".
n1.a = fun1("Hello", "World");
n1.b = fun1("Hello", "Hello");
n1.c = fun2("Hello", "World");
n1.d = fun2("Hello", "Hello");
n1.e = fun3("Hello", "Hello", "World", "Foo");
// Should be valid
n1.a = takeReturnString(n1.a);
n1.b = takeReturnString(n1.b);
n1.c = takeReturnString(n1.c);
n1.d = takeReturnString(n1.d);
n1.e = takeReturnString(n1.e);
// Passing these as arguments should cause an error.
n1.a = takeReturnHello(n1.a);
n1.b = takeReturnHello(n1.b);
n1.c = takeReturnHello(n1.c);
n1.d = takeReturnHello(n1.d);
n1.e = takeReturnHello(n1.e);
// Passing these as arguments should cause an error.
n1.a = takeReturnHelloWorld(n1.a);
n1.b = takeReturnHelloWorld(n1.b);
n1.c = takeReturnHelloWorld(n1.c);
n1.d = takeReturnHelloWorld(n1.d);
n1.e = takeReturnHelloWorld(n1.e);
})(n1 || (n1 = {}));
var n2;
(function (n2) {
// The following (regardless of errors) should come back typed
// as "Hello" (or "Hello" | "Hello").
n2.a = fun1 < "Hello" > ("Hello", "Hello");
n2.b = fun1 < "Hello" > ("Hello", "World");
n2.c = fun2 < "Hello";
"Hello" > ("Hello", "Hello");
n2.d = fun2 < "Hello";
"Hello" > ("Hello", "World");
n2.e = fun3 < "Hello" > ("Hello", "World");
// Assignment from the returned value should cause an error.
n2.a = takeReturnString(n2.a);
n2.b = takeReturnString(n2.b);
n2.c = takeReturnString(n2.c);
n2.d = takeReturnString(n2.d);
n2.e = takeReturnString(n2.e);
// Should be valid
n2.a = takeReturnHello(n2.a);
n2.b = takeReturnHello(n2.b);
n2.c = takeReturnHello(n2.c);
n2.d = takeReturnHello(n2.d);
n2.e = takeReturnHello(n2.e);
// Assignment from the returned value should cause an error.
n2.a = takeReturnHelloWorld(n2.a);
n2.b = takeReturnHelloWorld(n2.b);
n2.c = takeReturnHelloWorld(n2.c);
n2.d = takeReturnHelloWorld(n2.d);
n2.e = takeReturnHelloWorld(n2.e);
})(n2 || (n2 = {}));
var n3;
(function (n3) {
// The following (regardless of errors) should come back typed
// as "Hello" | "World" (or "World" | "Hello").
n3.a = fun2 < "Hello";
"World" > ("Hello", "World");
n3.b = fun2 < "Hello";
"World" > ("World", "Hello");
n3.c = fun2 < "World";
"Hello" > ("Hello", "Hello");
n3.d = fun2 < "World";
"Hello" > ("World", "World");
n3.e = fun3 < "Hello" | "World" > ("Hello", "World");
// Assignment from the returned value should cause an error.
n3.a = takeReturnString(n3.a);
n3.b = takeReturnString(n3.b);
n3.c = takeReturnString(n3.c);
n3.d = takeReturnString(n3.d);
n3.e = takeReturnString(n3.e);
// Passing these as arguments should cause an error.
n3.a = takeReturnHello(n3.a);
n3.b = takeReturnHello(n3.b);
n3.c = takeReturnHello(n3.c);
n3.d = takeReturnHello(n3.d);
n3.e = takeReturnHello(n3.e);
// Both should be valid.
n3.a = takeReturnHelloWorld(n3.a);
n3.b = takeReturnHelloWorld(n3.b);
n3.c = takeReturnHelloWorld(n3.c);
n3.d = takeReturnHelloWorld(n3.d);
n3.e = takeReturnHelloWorld(n3.e);
})(n3 || (n3 = {}));