Merge pull request #17765 from tycho01/6229-known-length-tuples

add `strictTuples` flag giving tuples known length
This commit is contained in:
Nathan Shively-Sanders 2017-11-08 15:38:39 -08:00 коммит произвёл GitHub
Родитель b7d36b2e8d c1c7926735
Коммит 90f87ef180
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
53 изменённых файлов: 847 добавлений и 298 удалений

Просмотреть файл

@ -7310,6 +7310,9 @@ namespace ts {
property.type = typeParameter;
properties.push(property);
}
const lengthSymbol = createSymbol(SymbolFlags.Property, "length" as __String);
lengthSymbol.type = getLiteralType(arity);
properties.push(lengthSymbol);
const type = <GenericType & InterfaceTypeWithDeclaredMembers>createObjectType(ObjectFlags.Tuple | ObjectFlags.Reference);
type.typeParameters = typeParameters;
type.outerTypeParameters = undefined;

Просмотреть файл

@ -1,52 +1,49 @@
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(13,12): error TS2493: Tuple type '[string, number]' with length '2' cannot be assigned to tuple with length '3'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(14,12): error TS2460: Type 'StrNum' has no property '2'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(15,5): error TS2461: Type '{ 0: string; 1: number; }' is not an array type.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(15,12): error TS2460: Type '{ 0: string; 1: number; }' has no property '2'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(16,5): error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(15,12): error TS2493: Tuple type '[string, number]' with length '2' cannot be assigned to tuple with length '3'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(16,12): error TS2460: Type 'StrNum' has no property '2'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(17,5): error TS2461: Type '{ 0: string; 1: number; length: 2; }' is not an array type.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(17,12): error TS2460: Type '{ 0: string; 1: number; length: 2; }' has no property '2'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(18,5): error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'.
Property '2' is missing in type '[string, number]'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(17,5): error TS2322: Type 'StrNum' is not assignable to type '[number, number, number]'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(19,5): error TS2322: Type 'StrNum' is not assignable to type '[number, number, number]'.
Property '2' is missing in type 'StrNum'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(18,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, number, number]'.
Property '2' is missing in type '{ 0: string; 1: number; }'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(19,5): error TS2322: Type '[string, number]' is not assignable to type '[string, number, number]'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(20,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, number, number]'.
Property '2' is missing in type '{ 0: string; 1: number; length: 2; }'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(21,5): error TS2322: Type '[string, number]' is not assignable to type '[string, number, number]'.
Property '2' is missing in type '[string, number]'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(20,5): error TS2322: Type 'StrNum' is not assignable to type '[string, number, number]'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(22,5): error TS2322: Type 'StrNum' is not assignable to type '[string, number, number]'.
Property '2' is missing in type 'StrNum'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(21,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string, number, number]'.
Property '2' is missing in type '{ 0: string; 1: number; }'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(22,5): error TS2322: Type '[string, number]' is not assignable to type '[number]'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(23,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string, number, number]'.
Property '2' is missing in type '{ 0: string; 1: number; length: 2; }'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(24,5): error TS2322: Type '[string, number]' is not assignable to type '[number]'.
Types of property '0' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(23,5): error TS2322: Type 'StrNum' is not assignable to type '[number]'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(25,5): error TS2322: Type 'StrNum' is not assignable to type '[number]'.
Types of property '0' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(24,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number]'.
Property 'length' is missing in type '{ 0: string; 1: number; }'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(25,5): error TS2322: Type '[string, number]' is not assignable to type '[string]'.
Types of property 'pop' are incompatible.
Type '() => string | number' is not assignable to type '() => string'.
Type 'string | number' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(26,5): error TS2322: Type 'StrNum' is not assignable to type '[string]'.
Types of property 'pop' are incompatible.
Type '() => string | number' is not assignable to type '() => string'.
Type 'string | number' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(27,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string]'.
Property 'length' is missing in type '{ 0: string; 1: number; }'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(28,5): error TS2322: Type '[string, number]' is not assignable to type '[number, string]'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(26,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number]'.
Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(27,5): error TS2322: Type '[string, number]' is not assignable to type '[string]'.
Types of property 'length' are incompatible.
Type '2' is not assignable to type '1'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(28,5): error TS2322: Type 'StrNum' is not assignable to type '[string]'.
Types of property 'length' are incompatible.
Type '2' is not assignable to type '1'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(29,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string]'.
Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error TS2322: Type '[string, number]' is not assignable to type '[number, string]'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(29,5): error TS2322: Type 'StrNum' is not assignable to type '[number, string]'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(31,5): error TS2322: Type 'StrNum' is not assignable to type '[number, string]'.
Types of property '0' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, string]'.
Property 'length' is missing in type '{ 0: string; 1: number; }'.
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, string]'.
Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
==== tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts (19 errors) ====
interface StrNum extends Array<string|number> {
0: string;
1: number;
length: 2;
}
var x: [string, number];
@ -54,6 +51,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error
var z: {
0: string;
1: number;
length: 2;
}
var [a, b, c] = x;
@ -64,9 +62,9 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error
!!! error TS2460: Type 'StrNum' has no property '2'.
var [g, h, i] = z;
~~~~~~~~~
!!! error TS2461: Type '{ 0: string; 1: number; }' is not an array type.
!!! error TS2461: Type '{ 0: string; 1: number; length: 2; }' is not an array type.
~
!!! error TS2460: Type '{ 0: string; 1: number; }' has no property '2'.
!!! error TS2460: Type '{ 0: string; 1: number; length: 2; }' has no property '2'.
var j1: [number, number, number] = x;
~~
!!! error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'.
@ -77,8 +75,8 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error
!!! error TS2322: Property '2' is missing in type 'StrNum'.
var j3: [number, number, number] = z;
~~
!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, number, number]'.
!!! error TS2322: Property '2' is missing in type '{ 0: string; 1: number; }'.
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, number, number]'.
!!! error TS2322: Property '2' is missing in type '{ 0: string; 1: number; length: 2; }'.
var k1: [string, number, number] = x;
~~
!!! error TS2322: Type '[string, number]' is not assignable to type '[string, number, number]'.
@ -89,8 +87,8 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error
!!! error TS2322: Property '2' is missing in type 'StrNum'.
var k3: [string, number, number] = z;
~~
!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string, number, number]'.
!!! error TS2322: Property '2' is missing in type '{ 0: string; 1: number; }'.
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string, number, number]'.
!!! error TS2322: Property '2' is missing in type '{ 0: string; 1: number; length: 2; }'.
var l1: [number] = x;
~~
!!! error TS2322: Type '[string, number]' is not assignable to type '[number]'.
@ -103,26 +101,22 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error
!!! error TS2322: Type 'string' is not assignable to type 'number'.
var l3: [number] = z;
~~
!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number]'.
!!! error TS2322: Property 'length' is missing in type '{ 0: string; 1: number; }'.
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number]'.
!!! error TS2322: Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
var m1: [string] = x;
~~
!!! error TS2322: Type '[string, number]' is not assignable to type '[string]'.
!!! error TS2322: Types of property 'pop' are incompatible.
!!! error TS2322: Type '() => string | number' is not assignable to type '() => string'.
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '2' is not assignable to type '1'.
var m2: [string] = y;
~~
!!! error TS2322: Type 'StrNum' is not assignable to type '[string]'.
!!! error TS2322: Types of property 'pop' are incompatible.
!!! error TS2322: Type '() => string | number' is not assignable to type '() => string'.
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '2' is not assignable to type '1'.
var m3: [string] = z;
~~
!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string]'.
!!! error TS2322: Property 'length' is missing in type '{ 0: string; 1: number; }'.
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string]'.
!!! error TS2322: Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
var n1: [number, string] = x;
~~
!!! error TS2322: Type '[string, number]' is not assignable to type '[number, string]'.
@ -134,8 +128,8 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error
!!! error TS2322: Type 'string' is not assignable to type 'number'.
var n3: [number, string] = z;
~~
!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, string]'.
!!! error TS2322: Property 'length' is missing in type '{ 0: string; 1: number; }'.
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, string]'.
!!! error TS2322: Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
var o1: [string, number] = x;
var o2: [string, number] = y;
var o3: [string, number] = y;

Просмотреть файл

@ -2,6 +2,7 @@
interface StrNum extends Array<string|number> {
0: string;
1: number;
length: 2;
}
var x: [string, number];
@ -9,6 +10,7 @@ var y: StrNum
var z: {
0: string;
1: number;
length: 2;
}
var [a, b, c] = x;

Просмотреть файл

@ -5,109 +5,113 @@ interface StrNum extends Array<string|number> {
0: string;
1: number;
length: 2;
>length : Symbol(StrNum.length, Decl(arityAndOrderCompatibility01.ts, 2, 14))
}
var x: [string, number];
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 5, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 6, 3))
var y: StrNum
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 6, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 7, 3))
>StrNum : Symbol(StrNum, Decl(arityAndOrderCompatibility01.ts, 0, 0))
var z: {
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 7, 3))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 8, 3))
0: string;
1: number;
length: 2;
>length : Symbol(length, Decl(arityAndOrderCompatibility01.ts, 10, 14))
}
var [a, b, c] = x;
>a : Symbol(a, Decl(arityAndOrderCompatibility01.ts, 12, 5))
>b : Symbol(b, Decl(arityAndOrderCompatibility01.ts, 12, 7))
>c : Symbol(c, Decl(arityAndOrderCompatibility01.ts, 12, 10))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 5, 3))
>a : Symbol(a, Decl(arityAndOrderCompatibility01.ts, 14, 5))
>b : Symbol(b, Decl(arityAndOrderCompatibility01.ts, 14, 7))
>c : Symbol(c, Decl(arityAndOrderCompatibility01.ts, 14, 10))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 6, 3))
var [d, e, f] = y;
>d : Symbol(d, Decl(arityAndOrderCompatibility01.ts, 13, 5))
>e : Symbol(e, Decl(arityAndOrderCompatibility01.ts, 13, 7))
>f : Symbol(f, Decl(arityAndOrderCompatibility01.ts, 13, 10))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 6, 3))
>d : Symbol(d, Decl(arityAndOrderCompatibility01.ts, 15, 5))
>e : Symbol(e, Decl(arityAndOrderCompatibility01.ts, 15, 7))
>f : Symbol(f, Decl(arityAndOrderCompatibility01.ts, 15, 10))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 7, 3))
var [g, h, i] = z;
>g : Symbol(g, Decl(arityAndOrderCompatibility01.ts, 14, 5))
>h : Symbol(h, Decl(arityAndOrderCompatibility01.ts, 14, 7))
>i : Symbol(i, Decl(arityAndOrderCompatibility01.ts, 14, 10))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 7, 3))
>g : Symbol(g, Decl(arityAndOrderCompatibility01.ts, 16, 5))
>h : Symbol(h, Decl(arityAndOrderCompatibility01.ts, 16, 7))
>i : Symbol(i, Decl(arityAndOrderCompatibility01.ts, 16, 10))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 8, 3))
var j1: [number, number, number] = x;
>j1 : Symbol(j1, Decl(arityAndOrderCompatibility01.ts, 15, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 5, 3))
>j1 : Symbol(j1, Decl(arityAndOrderCompatibility01.ts, 17, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 6, 3))
var j2: [number, number, number] = y;
>j2 : Symbol(j2, Decl(arityAndOrderCompatibility01.ts, 16, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 6, 3))
>j2 : Symbol(j2, Decl(arityAndOrderCompatibility01.ts, 18, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 7, 3))
var j3: [number, number, number] = z;
>j3 : Symbol(j3, Decl(arityAndOrderCompatibility01.ts, 17, 3))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 7, 3))
>j3 : Symbol(j3, Decl(arityAndOrderCompatibility01.ts, 19, 3))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 8, 3))
var k1: [string, number, number] = x;
>k1 : Symbol(k1, Decl(arityAndOrderCompatibility01.ts, 18, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 5, 3))
>k1 : Symbol(k1, Decl(arityAndOrderCompatibility01.ts, 20, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 6, 3))
var k2: [string, number, number] = y;
>k2 : Symbol(k2, Decl(arityAndOrderCompatibility01.ts, 19, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 6, 3))
>k2 : Symbol(k2, Decl(arityAndOrderCompatibility01.ts, 21, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 7, 3))
var k3: [string, number, number] = z;
>k3 : Symbol(k3, Decl(arityAndOrderCompatibility01.ts, 20, 3))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 7, 3))
>k3 : Symbol(k3, Decl(arityAndOrderCompatibility01.ts, 22, 3))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 8, 3))
var l1: [number] = x;
>l1 : Symbol(l1, Decl(arityAndOrderCompatibility01.ts, 21, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 5, 3))
>l1 : Symbol(l1, Decl(arityAndOrderCompatibility01.ts, 23, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 6, 3))
var l2: [number] = y;
>l2 : Symbol(l2, Decl(arityAndOrderCompatibility01.ts, 22, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 6, 3))
>l2 : Symbol(l2, Decl(arityAndOrderCompatibility01.ts, 24, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 7, 3))
var l3: [number] = z;
>l3 : Symbol(l3, Decl(arityAndOrderCompatibility01.ts, 23, 3))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 7, 3))
>l3 : Symbol(l3, Decl(arityAndOrderCompatibility01.ts, 25, 3))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 8, 3))
var m1: [string] = x;
>m1 : Symbol(m1, Decl(arityAndOrderCompatibility01.ts, 24, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 5, 3))
>m1 : Symbol(m1, Decl(arityAndOrderCompatibility01.ts, 26, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 6, 3))
var m2: [string] = y;
>m2 : Symbol(m2, Decl(arityAndOrderCompatibility01.ts, 25, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 6, 3))
>m2 : Symbol(m2, Decl(arityAndOrderCompatibility01.ts, 27, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 7, 3))
var m3: [string] = z;
>m3 : Symbol(m3, Decl(arityAndOrderCompatibility01.ts, 26, 3))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 7, 3))
>m3 : Symbol(m3, Decl(arityAndOrderCompatibility01.ts, 28, 3))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 8, 3))
var n1: [number, string] = x;
>n1 : Symbol(n1, Decl(arityAndOrderCompatibility01.ts, 27, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 5, 3))
>n1 : Symbol(n1, Decl(arityAndOrderCompatibility01.ts, 29, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 6, 3))
var n2: [number, string] = y;
>n2 : Symbol(n2, Decl(arityAndOrderCompatibility01.ts, 28, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 6, 3))
>n2 : Symbol(n2, Decl(arityAndOrderCompatibility01.ts, 30, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 7, 3))
var n3: [number, string] = z;
>n3 : Symbol(n3, Decl(arityAndOrderCompatibility01.ts, 29, 3))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 7, 3))
>n3 : Symbol(n3, Decl(arityAndOrderCompatibility01.ts, 31, 3))
>z : Symbol(z, Decl(arityAndOrderCompatibility01.ts, 8, 3))
var o1: [string, number] = x;
>o1 : Symbol(o1, Decl(arityAndOrderCompatibility01.ts, 30, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 5, 3))
>o1 : Symbol(o1, Decl(arityAndOrderCompatibility01.ts, 32, 3))
>x : Symbol(x, Decl(arityAndOrderCompatibility01.ts, 6, 3))
var o2: [string, number] = y;
>o2 : Symbol(o2, Decl(arityAndOrderCompatibility01.ts, 31, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 6, 3))
>o2 : Symbol(o2, Decl(arityAndOrderCompatibility01.ts, 33, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 7, 3))
var o3: [string, number] = y;
>o3 : Symbol(o3, Decl(arityAndOrderCompatibility01.ts, 32, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 6, 3))
>o3 : Symbol(o3, Decl(arityAndOrderCompatibility01.ts, 34, 3))
>y : Symbol(y, Decl(arityAndOrderCompatibility01.ts, 7, 3))

Просмотреть файл

@ -5,6 +5,8 @@ interface StrNum extends Array<string|number> {
0: string;
1: number;
length: 2;
>length : 2
}
var x: [string, number];
@ -15,10 +17,12 @@ var y: StrNum
>StrNum : StrNum
var z: {
>z : { 0: string; 1: number; }
>z : { 0: string; 1: number; length: 2; }
0: string;
1: number;
length: 2;
>length : 2
}
var [a, b, c] = x;
@ -37,7 +41,7 @@ var [g, h, i] = z;
>g : string
>h : number
>i : any
>z : { 0: string; 1: number; }
>z : { 0: string; 1: number; length: 2; }
var j1: [number, number, number] = x;
>j1 : [number, number, number]
@ -49,7 +53,7 @@ var j2: [number, number, number] = y;
var j3: [number, number, number] = z;
>j3 : [number, number, number]
>z : { 0: string; 1: number; }
>z : { 0: string; 1: number; length: 2; }
var k1: [string, number, number] = x;
>k1 : [string, number, number]
@ -61,7 +65,7 @@ var k2: [string, number, number] = y;
var k3: [string, number, number] = z;
>k3 : [string, number, number]
>z : { 0: string; 1: number; }
>z : { 0: string; 1: number; length: 2; }
var l1: [number] = x;
>l1 : [number]
@ -73,7 +77,7 @@ var l2: [number] = y;
var l3: [number] = z;
>l3 : [number]
>z : { 0: string; 1: number; }
>z : { 0: string; 1: number; length: 2; }
var m1: [string] = x;
>m1 : [string]
@ -85,7 +89,7 @@ var m2: [string] = y;
var m3: [string] = z;
>m3 : [string]
>z : { 0: string; 1: number; }
>z : { 0: string; 1: number; length: 2; }
var n1: [number, string] = x;
>n1 : [number, string]
@ -97,7 +101,7 @@ var n2: [number, string] = y;
var n3: [number, string] = z;
>n3 : [number, string]
>z : { 0: string; 1: number; }
>z : { 0: string; 1: number; length: 2; }
var o1: [string, number] = x;
>o1 : [string, number]

Просмотреть файл

@ -1,27 +1,37 @@
tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(6,5): error TS2322: Type '[number, number, number, number]' is not assignable to type '[number, number, number]'.
Types of property 'length' are incompatible.
Type '4' is not assignable to type '3'.
tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(7,5): error TS2322: Type '[number, number, number, string]' is not assignable to type '[string | number, string | number, string | number]'.
Types of property 'length' are incompatible.
Type '4' is not assignable to type '3'.
tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(8,5): error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, number]'.
Types of property 'pop' are incompatible.
Type '() => string | number' is not assignable to type '() => number'.
Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
Types of property 'length' are incompatible.
Type '4' is not assignable to type '3'.
tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(14,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'.
Property '0' is missing in type 'number[]'.
==== tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts (2 errors) ====
==== tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts (4 errors) ====
// In a contextually typed array literal expression containing no spread elements, an element expression at index N is contextually typed by
// the type of the property with the numeric name N in the contextual type, if any, or otherwise
// the numeric index type of the contextual type, if any.
var array = [1, 2, 3];
var array1 = [true, 2, 3]; // Contextual type by the numeric index type of the contextual type
var tup: [number, number, number] = [1, 2, 3, 4];
~~~
!!! error TS2322: Type '[number, number, number, number]' is not assignable to type '[number, number, number]'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '4' is not assignable to type '3'.
var tup1: [number|string, number|string, number|string] = [1, 2, 3, "string"];
~~~~
!!! error TS2322: Type '[number, number, number, string]' is not assignable to type '[string | number, string | number, string | number]'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '4' is not assignable to type '3'.
var tup2: [number, number, number] = [1, 2, 3, "string"]; // Error
~~~~
!!! error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, number]'.
!!! error TS2322: Types of property 'pop' are incompatible.
!!! error TS2322: Type '() => string | number' is not assignable to type '() => number'.
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '4' is not assignable to type '3'.
// In a contextually typed array literal expression containing one or more spread elements,
// an element expression at index N is contextually typed by the numeric index type of the contextual type, if any.

Просмотреть файл

@ -3,10 +3,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(10,5): error
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(11,5): error TS2322: Type '["string", number, boolean]' is not assignable to type '[boolean, string, number]'.
Type '"string"' is not assignable to type 'boolean'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'.
Types of property 'pop' are incompatible.
Type '() => string | number | boolean' is not assignable to type '() => number'.
Type 'string | number | boolean' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
Types of property 'length' are incompatible.
Type '4' is not assignable to type '2'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error TS2322: Type '(number[] | string[])[]' is not assignable to type 'tup'.
Property '0' is missing in type '(number[] | string[])[]'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'.
@ -46,10 +44,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error
var [b1, b2]: [number, number] = [1, 2, "string", true];
~~~~~~~~
!!! error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'.
!!! error TS2322: Types of property 'pop' are incompatible.
!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => number'.
!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '4' is not assignable to type '2'.
// The resulting type an array literal expression is determined as follows:
// - the resulting type is an array type with an element type that is the union of the types of the

Просмотреть файл

@ -1,13 +1,21 @@
tests/cases/conformance/types/tuple/castingTuple.ts(28,10): error TS2352: Type '[number, string]' cannot be converted to type '[number, number]'.
tests/cases/conformance/types/tuple/castingTuple.ts(13,23): error TS2352: Type '[number, string]' cannot be converted to type '[number, string, boolean]'.
Property '2' is missing in type '[number, string]'.
tests/cases/conformance/types/tuple/castingTuple.ts(14,15): error TS2352: Type '[number, string, boolean]' cannot be converted to type '[number, string]'.
Types of property 'length' are incompatible.
Type '3' is not comparable to type '2'.
tests/cases/conformance/types/tuple/castingTuple.ts(15,14): error TS2352: Type '[number, string]' cannot be converted to type '[number, string, boolean]'.
tests/cases/conformance/types/tuple/castingTuple.ts(18,21): error TS2352: Type '[C, D]' cannot be converted to type '[C, D, A]'.
Property '2' is missing in type '[C, D]'.
tests/cases/conformance/types/tuple/castingTuple.ts(30,10): error TS2352: Type '[number, string]' cannot be converted to type '[number, number]'.
Type 'string' is not comparable to type 'number'.
tests/cases/conformance/types/tuple/castingTuple.ts(29,10): error TS2352: Type '[C, D]' cannot be converted to type '[A, I]'.
tests/cases/conformance/types/tuple/castingTuple.ts(31,10): error TS2352: Type '[C, D]' cannot be converted to type '[A, I]'.
Type 'C' is not comparable to type 'A'.
Property 'a' is missing in type 'C'.
tests/cases/conformance/types/tuple/castingTuple.ts(30,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' has type '{}[]' at tests/cases/conformance/types/tuple/castingTuple.ts 20:4, but here has type 'number[]'.
tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot find name 't4'.
tests/cases/conformance/types/tuple/castingTuple.ts(32,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' has type '{}[]' at tests/cases/conformance/types/tuple/castingTuple.ts 22:4, but here has type 'number[]'.
tests/cases/conformance/types/tuple/castingTuple.ts(33,1): error TS2304: Cannot find name 't4'.
==== tests/cases/conformance/types/tuple/castingTuple.ts (4 errors) ====
==== tests/cases/conformance/types/tuple/castingTuple.ts (8 errors) ====
interface I { }
class A { a = 10; }
class C implements I { c };
@ -21,9 +29,23 @@ tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot
var numStrTuple: [number, string] = [5, "foo"];
var emptyObjTuple = <[{}, {}]>numStrTuple;
var numStrBoolTuple = <[number, string, boolean]>numStrTuple;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2352: Type '[number, string]' cannot be converted to type '[number, string, boolean]'.
!!! error TS2352: Property '2' is missing in type '[number, string]'.
var shorter = numStrBoolTuple as [number, string]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2352: Type '[number, string, boolean]' cannot be converted to type '[number, string]'.
!!! error TS2352: Types of property 'length' are incompatible.
!!! error TS2352: Type '3' is not comparable to type '2'.
var longer = numStrTuple as [number, string, boolean]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2352: Type '[number, string]' cannot be converted to type '[number, string, boolean]'.
var classCDTuple: [C, D] = [new C(), new D()];
var interfaceIITuple = <[I, I]>classCDTuple;
var classCDATuple = <[C, D, A]>classCDTuple;
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2352: Type '[C, D]' cannot be converted to type '[C, D, A]'.
!!! error TS2352: Property '2' is missing in type '[C, D]'.
var eleFromCDA1 = classCDATuple[2]; // A
var eleFromCDA2 = classCDATuple[5]; // C | D | A
var t10: [E1, E2] = [E1.one, E2.one];
@ -46,7 +68,7 @@ tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot
!!! error TS2352: Property 'a' is missing in type 'C'.
var array1 = <number[]>numStrTuple;
~~~~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' has type '{}[]' at tests/cases/conformance/types/tuple/castingTuple.ts 20:4, but here has type 'number[]'.
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' has type '{}[]' at tests/cases/conformance/types/tuple/castingTuple.ts 22:4, but here has type 'number[]'.
t4[2] = 10;
~~
!!! error TS2304: Cannot find name 't4'.

Просмотреть файл

@ -12,6 +12,8 @@ enum E2 { one }
var numStrTuple: [number, string] = [5, "foo"];
var emptyObjTuple = <[{}, {}]>numStrTuple;
var numStrBoolTuple = <[number, string, boolean]>numStrTuple;
var shorter = numStrBoolTuple as [number, string]
var longer = numStrTuple as [number, string, boolean]
var classCDTuple: [C, D] = [new C(), new D()];
var interfaceIITuple = <[I, I]>classCDTuple;
var classCDATuple = <[C, D, A]>classCDTuple;
@ -89,6 +91,8 @@ var E2;
var numStrTuple = [5, "foo"];
var emptyObjTuple = numStrTuple;
var numStrBoolTuple = numStrTuple;
var shorter = numStrBoolTuple;
var longer = numStrTuple;
var classCDTuple = [new C(), new D()];
var interfaceIITuple = classCDTuple;
var classCDATuple = classCDTuple;

Просмотреть файл

@ -46,37 +46,45 @@ var numStrBoolTuple = <[number, string, boolean]>numStrTuple;
>numStrBoolTuple : Symbol(numStrBoolTuple, Decl(castingTuple.ts, 12, 3))
>numStrTuple : Symbol(numStrTuple, Decl(castingTuple.ts, 10, 3))
var shorter = numStrBoolTuple as [number, string]
>shorter : Symbol(shorter, Decl(castingTuple.ts, 13, 3))
>numStrBoolTuple : Symbol(numStrBoolTuple, Decl(castingTuple.ts, 12, 3))
var longer = numStrTuple as [number, string, boolean]
>longer : Symbol(longer, Decl(castingTuple.ts, 14, 3))
>numStrTuple : Symbol(numStrTuple, Decl(castingTuple.ts, 10, 3))
var classCDTuple: [C, D] = [new C(), new D()];
>classCDTuple : Symbol(classCDTuple, Decl(castingTuple.ts, 13, 3))
>classCDTuple : Symbol(classCDTuple, Decl(castingTuple.ts, 15, 3))
>C : Symbol(C, Decl(castingTuple.ts, 1, 19))
>D : Symbol(D, Decl(castingTuple.ts, 2, 27))
>C : Symbol(C, Decl(castingTuple.ts, 1, 19))
>D : Symbol(D, Decl(castingTuple.ts, 2, 27))
var interfaceIITuple = <[I, I]>classCDTuple;
>interfaceIITuple : Symbol(interfaceIITuple, Decl(castingTuple.ts, 14, 3))
>interfaceIITuple : Symbol(interfaceIITuple, Decl(castingTuple.ts, 16, 3))
>I : Symbol(I, Decl(castingTuple.ts, 0, 0))
>I : Symbol(I, Decl(castingTuple.ts, 0, 0))
>classCDTuple : Symbol(classCDTuple, Decl(castingTuple.ts, 13, 3))
>classCDTuple : Symbol(classCDTuple, Decl(castingTuple.ts, 15, 3))
var classCDATuple = <[C, D, A]>classCDTuple;
>classCDATuple : Symbol(classCDATuple, Decl(castingTuple.ts, 15, 3))
>classCDATuple : Symbol(classCDATuple, Decl(castingTuple.ts, 17, 3))
>C : Symbol(C, Decl(castingTuple.ts, 1, 19))
>D : Symbol(D, Decl(castingTuple.ts, 2, 27))
>A : Symbol(A, Decl(castingTuple.ts, 0, 15))
>classCDTuple : Symbol(classCDTuple, Decl(castingTuple.ts, 13, 3))
>classCDTuple : Symbol(classCDTuple, Decl(castingTuple.ts, 15, 3))
var eleFromCDA1 = classCDATuple[2]; // A
>eleFromCDA1 : Symbol(eleFromCDA1, Decl(castingTuple.ts, 16, 3))
>classCDATuple : Symbol(classCDATuple, Decl(castingTuple.ts, 15, 3))
>eleFromCDA1 : Symbol(eleFromCDA1, Decl(castingTuple.ts, 18, 3))
>classCDATuple : Symbol(classCDATuple, Decl(castingTuple.ts, 17, 3))
>2 : Symbol(2)
var eleFromCDA2 = classCDATuple[5]; // C | D | A
>eleFromCDA2 : Symbol(eleFromCDA2, Decl(castingTuple.ts, 17, 3))
>classCDATuple : Symbol(classCDATuple, Decl(castingTuple.ts, 15, 3))
>eleFromCDA2 : Symbol(eleFromCDA2, Decl(castingTuple.ts, 19, 3))
>classCDATuple : Symbol(classCDATuple, Decl(castingTuple.ts, 17, 3))
var t10: [E1, E2] = [E1.one, E2.one];
>t10 : Symbol(t10, Decl(castingTuple.ts, 18, 3))
>t10 : Symbol(t10, Decl(castingTuple.ts, 20, 3))
>E1 : Symbol(E1, Decl(castingTuple.ts, 5, 24))
>E2 : Symbol(E2, Decl(castingTuple.ts, 6, 15))
>E1.one : Symbol(E1.one, Decl(castingTuple.ts, 6, 9))
@ -87,45 +95,45 @@ var t10: [E1, E2] = [E1.one, E2.one];
>one : Symbol(E2.one, Decl(castingTuple.ts, 7, 9))
var t11 = <[number, number]>t10;
>t11 : Symbol(t11, Decl(castingTuple.ts, 19, 3))
>t10 : Symbol(t10, Decl(castingTuple.ts, 18, 3))
>t11 : Symbol(t11, Decl(castingTuple.ts, 21, 3))
>t10 : Symbol(t10, Decl(castingTuple.ts, 20, 3))
var array1 = <{}[]>emptyObjTuple;
>array1 : Symbol(array1, Decl(castingTuple.ts, 20, 3), Decl(castingTuple.ts, 29, 3))
>array1 : Symbol(array1, Decl(castingTuple.ts, 22, 3), Decl(castingTuple.ts, 31, 3))
>emptyObjTuple : Symbol(emptyObjTuple, Decl(castingTuple.ts, 11, 3))
var unionTuple: [C, string | number] = [new C(), "foo"];
>unionTuple : Symbol(unionTuple, Decl(castingTuple.ts, 21, 3))
>unionTuple : Symbol(unionTuple, Decl(castingTuple.ts, 23, 3))
>C : Symbol(C, Decl(castingTuple.ts, 1, 19))
>C : Symbol(C, Decl(castingTuple.ts, 1, 19))
var unionTuple2: [C, string | number, D] = [new C(), "foo", new D()];
>unionTuple2 : Symbol(unionTuple2, Decl(castingTuple.ts, 22, 3))
>unionTuple2 : Symbol(unionTuple2, Decl(castingTuple.ts, 24, 3))
>C : Symbol(C, Decl(castingTuple.ts, 1, 19))
>D : Symbol(D, Decl(castingTuple.ts, 2, 27))
>C : Symbol(C, Decl(castingTuple.ts, 1, 19))
>D : Symbol(D, Decl(castingTuple.ts, 2, 27))
var unionTuple3: [number, string| number] = [10, "foo"];
>unionTuple3 : Symbol(unionTuple3, Decl(castingTuple.ts, 23, 3))
>unionTuple3 : Symbol(unionTuple3, Decl(castingTuple.ts, 25, 3))
var unionTuple4 = <[number, number]>unionTuple3;
>unionTuple4 : Symbol(unionTuple4, Decl(castingTuple.ts, 24, 3))
>unionTuple3 : Symbol(unionTuple3, Decl(castingTuple.ts, 23, 3))
>unionTuple4 : Symbol(unionTuple4, Decl(castingTuple.ts, 26, 3))
>unionTuple3 : Symbol(unionTuple3, Decl(castingTuple.ts, 25, 3))
// error
var t3 = <[number, number]>numStrTuple;
>t3 : Symbol(t3, Decl(castingTuple.ts, 27, 3))
>t3 : Symbol(t3, Decl(castingTuple.ts, 29, 3))
>numStrTuple : Symbol(numStrTuple, Decl(castingTuple.ts, 10, 3))
var t9 = <[A, I]>classCDTuple;
>t9 : Symbol(t9, Decl(castingTuple.ts, 28, 3))
>t9 : Symbol(t9, Decl(castingTuple.ts, 30, 3))
>A : Symbol(A, Decl(castingTuple.ts, 0, 15))
>I : Symbol(I, Decl(castingTuple.ts, 0, 0))
>classCDTuple : Symbol(classCDTuple, Decl(castingTuple.ts, 13, 3))
>classCDTuple : Symbol(classCDTuple, Decl(castingTuple.ts, 15, 3))
var array1 = <number[]>numStrTuple;
>array1 : Symbol(array1, Decl(castingTuple.ts, 20, 3), Decl(castingTuple.ts, 29, 3))
>array1 : Symbol(array1, Decl(castingTuple.ts, 22, 3), Decl(castingTuple.ts, 31, 3))
>numStrTuple : Symbol(numStrTuple, Decl(castingTuple.ts, 10, 3))
t4[2] = 10;

Просмотреть файл

@ -52,6 +52,16 @@ var numStrBoolTuple = <[number, string, boolean]>numStrTuple;
><[number, string, boolean]>numStrTuple : [number, string, boolean]
>numStrTuple : [number, string]
var shorter = numStrBoolTuple as [number, string]
>shorter : [number, string]
>numStrBoolTuple as [number, string] : [number, string]
>numStrBoolTuple : [number, string, boolean]
var longer = numStrTuple as [number, string, boolean]
>longer : [number, string, boolean]
>numStrTuple as [number, string, boolean] : [number, string, boolean]
>numStrTuple : [number, string]
var classCDTuple: [C, D] = [new C(), new D()];
>classCDTuple : [C, D]
>C : C

Просмотреть файл

@ -1,8 +1,6 @@
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(3,5): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
Types of property 'pop' are incompatible.
Type '() => string | number | boolean' is not assignable to type '() => string | number'.
Type 'string | number | boolean' is not assignable to type 'string | number'.
Type 'true' is not assignable to type 'string | number'.
Types of property 'length' are incompatible.
Type '3' is not assignable to type '2'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(15,1): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(18,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]'.
Type '{}' is not assignable to type '{ a: string; }'.
@ -10,10 +8,11 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(18,1): error TS23
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(19,1): error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]'.
Property '2' is missing in type '[number, string]'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(20,5): error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]'.
Types of property 'pop' are incompatible.
Type '() => string | number' is not assignable to type '() => string'.
Type 'string | number' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
Types of property 'length' are incompatible.
Type '3' is not assignable to type '2'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(23,1): error TS2322: Type '[C, string | number, D]' is not assignable to type '[C, string | number]'.
Types of property 'length' are incompatible.
Type '3' is not assignable to type '2'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(24,1): error TS2322: Type '[C, string | number]' is not assignable to type '[C, string | number, D]'.
Property '2' is missing in type '[C, string | number]'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS2322: Type '[number, string | number]' is not assignable to type '[number, string]'.
@ -21,16 +20,14 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS23
Type 'number' is not assignable to type 'string'.
==== tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts (7 errors) ====
==== tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts (8 errors) ====
// no error
var numStrTuple: [number, string] = [5, "hello"];
var numStrTuple2: [number, string] = [5, "foo", true];
~~~~~~~~~~~~
!!! error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
!!! error TS2322: Types of property 'pop' are incompatible.
!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => string | number'.
!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'string | number'.
!!! error TS2322: Type 'true' is not assignable to type 'string | number'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '3' is not assignable to type '2'.
var numStrBoolTuple: [number, string, boolean] = [5, "foo", true];
var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5];
var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]];
@ -59,13 +56,15 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS23
var strStrTuple: [string, string] = ["foo", "bar", 5];
~~~~~~~~~~~
!!! error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]'.
!!! error TS2322: Types of property 'pop' are incompatible.
!!! error TS2322: Type '() => string | number' is not assignable to type '() => string'.
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '3' is not assignable to type '2'.
unionTuple = unionTuple1;
unionTuple = unionTuple2;
~~~~~~~~~~
!!! error TS2322: Type '[C, string | number, D]' is not assignable to type '[C, string | number]'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '3' is not assignable to type '2'.
unionTuple2 = unionTuple;
~~~~~~~~~~~
!!! error TS2322: Type '[C, string | number]' is not assignable to type '[C, string | number, D]'.

Просмотреть файл

@ -1,8 +1,14 @@
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(12,4): error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
Types of property 'length' are incompatible.
Type '4' is not assignable to type '3'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(57,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
Types of property 'length' are incompatible.
Type '5' is not assignable to type '3'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(62,10): error TS2393: Duplicate function implementation.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(63,10): error TS2393: Duplicate function implementation.
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts (2 errors) ====
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts (4 errors) ====
// A parameter declaration may specify either an identifier or a binding pattern.
// The identifiers specified in parameter declarations and binding patterns
// in a parameter list must be unique within that parameter list.
@ -15,6 +21,10 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.
a1([1, 2, [["world"]]]);
a1([1, 2, [["world"]], 3]);
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
!!! error TS2345: Types of property 'length' are incompatible.
!!! error TS2345: Type '4' is not assignable to type '3'.
// If the declaration includes an initializer expression (which is permitted only
// when the parameter list occurs in conjunction with a function body),
@ -60,6 +70,10 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.
c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]]
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
!!! error TS2345: Types of property 'length' are incompatible.
!!! error TS2345: Type '5' is not assignable to type '3'.
// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
// or by including an initializer.

Просмотреть файл

@ -54,7 +54,7 @@ a1([1, 2, [["world"]]]);
a1([1, 2, [["world"]], 3]);
>a1([1, 2, [["world"]], 3]) : void
>a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void
>[1, 2, [["world"]], 3] : [number, number, string[][], number]
>[1, 2, [["world"]], 3] : (number | string[][])[]
>1 : 1
>2 : 2
>[["world"]] : string[][]
@ -304,11 +304,11 @@ c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
>c5([1, 2, [["string"]], false, true]) : void
>c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void
>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean]
>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[]
>1 : 1
>2 : 2
>[["string"]] : [[string]]
>["string"] : [string]
>[["string"]] : string[][]
>["string"] : string[]
>"string" : "string"
>false : false
>true : true

Просмотреть файл

@ -1,8 +1,14 @@
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts(12,4): error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
Types of property 'length' are incompatible.
Type '4' is not assignable to type '3'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts(57,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
Types of property 'length' are incompatible.
Type '5' is not assignable to type '3'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts(62,10): error TS2393: Duplicate function implementation.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts(63,10): error TS2393: Duplicate function implementation.
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts (2 errors) ====
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5iterable.ts (4 errors) ====
// A parameter declaration may specify either an identifier or a binding pattern.
// The identifiers specified in parameter declarations and binding patterns
// in a parameter list must be unique within that parameter list.
@ -15,6 +21,10 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5i
a1([1, 2, [["world"]]]);
a1([1, 2, [["world"]], 3]);
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
!!! error TS2345: Types of property 'length' are incompatible.
!!! error TS2345: Type '4' is not assignable to type '3'.
// If the declaration includes an initializer expression (which is permitted only
// when the parameter list occurs in conjunction with a function body),
@ -60,6 +70,10 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5i
c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]]
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
!!! error TS2345: Types of property 'length' are incompatible.
!!! error TS2345: Type '5' is not assignable to type '3'.
// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
// or by including an initializer.

Просмотреть файл

@ -54,7 +54,7 @@ a1([1, 2, [["world"]]]);
a1([1, 2, [["world"]], 3]);
>a1([1, 2, [["world"]], 3]) : void
>a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void
>[1, 2, [["world"]], 3] : [number, number, string[][], number]
>[1, 2, [["world"]], 3] : (number | string[][])[]
>1 : 1
>2 : 2
>[["world"]] : string[][]
@ -304,11 +304,11 @@ c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
>c5([1, 2, [["string"]], false, true]) : void
>c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void
>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean]
>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[]
>1 : 1
>2 : 2
>[["string"]] : [[string]]
>["string"] : [string]
>[["string"]] : string[][]
>["string"] : string[]
>"string" : "string"
>false : false
>true : true

Просмотреть файл

@ -1,9 +1,15 @@
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(14,4): error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
Types of property 'length' are incompatible.
Type '4' is not assignable to type '3'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(58,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
Types of property 'length' are incompatible.
Type '5' is not assignable to type '3'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(96,18): error TS2300: Duplicate identifier 'number'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(96,26): error TS2300: Duplicate identifier 'number'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(96,34): error TS2300: Duplicate identifier 'number'.
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts (3 errors) ====
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts (5 errors) ====
// Conformance for emitting ES6
// A parameter declaration may specify either an identifier or a binding pattern.
@ -18,6 +24,10 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.
a1([1, 2, [["world"]]]);
a1([1, 2, [["world"]], 3]);
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, string[][], number]' is not assignable to parameter of type '[number, number, string[][]]'.
!!! error TS2345: Types of property 'length' are incompatible.
!!! error TS2345: Type '4' is not assignable to type '3'.
// If the declaration includes an initializer expression (which is permitted only
@ -62,6 +72,10 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.
c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]]
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
!!! error TS2345: Types of property 'length' are incompatible.
!!! error TS2345: Type '5' is not assignable to type '3'.
// A parameter can be marked optional by following its name or binding pattern with a question mark (?)

Просмотреть файл

@ -56,7 +56,7 @@ a1([1, 2, [["world"]]]);
a1([1, 2, [["world"]], 3]);
>a1([1, 2, [["world"]], 3]) : void
>a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void
>[1, 2, [["world"]], 3] : [number, number, string[][], number]
>[1, 2, [["world"]], 3] : (number | string[][])[]
>1 : 1
>2 : 2
>[["world"]] : string[][]
@ -287,11 +287,11 @@ c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
>c5([1, 2, [["string"]], false, true]) : void
>c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void
>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean]
>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[]
>1 : 1
>2 : 2
>[["string"]] : [[string]]
>["string"] : [string]
>[["string"]] : string[][]
>["string"] : string[]
>"string" : "string"
>false : false
>true : true

Просмотреть файл

@ -2,10 +2,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,29): error TS1005: ',' expected.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(8,4): error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'.
Types of property 'pop' are incompatible.
Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'.
Type 'string | number | string[][]' is not assignable to type 'number | string[][]'.
Type 'string' is not assignable to type 'number | string[][]'.
Types of property 'length' are incompatible.
Type '4' is not assignable to type '3'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(23,14): error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'.
@ -64,10 +62,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
a0([1, 2, [["world"]], "string"]); // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'.
!!! error TS2345: Types of property 'pop' are incompatible.
!!! error TS2345: Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'.
!!! error TS2345: Type 'string | number | string[][]' is not assignable to type 'number | string[][]'.
!!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'.
!!! error TS2345: Types of property 'length' are incompatible.
!!! error TS2345: Type '4' is not assignable to type '3'.
// If the declaration includes an initializer expression (which is permitted only

Просмотреть файл

@ -0,0 +1,55 @@
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts(26,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
Types of property 'length' are incompatible.
Type '5' is not assignable to type '3'.
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts (1 errors) ====
// If the parameter is a rest parameter, the parameter type is any[]
// A type annotation for a rest parameter must denote an array type.
// RestParameter:
// ... Identifier TypeAnnotation(opt)
type arrayString = Array<String>
type someArray = Array<String> | number[];
type stringOrNumArray = Array<String|Number>;
function a1(...x: (number|string)[]) { }
function a2(...a) { }
function a3(...a: Array<String>) { }
function a4(...a: arrayString) { }
function a5(...a: stringOrNumArray) { }
function a9([a, b, [[c]]]) { }
function a10([a, b, [[c]], ...x]) { }
function a11([a, b, c, ...x]: number[]) { }
var array = [1, 2, 3];
var array2 = [true, false, "hello"];
a2([...array]);
a1(...array);
a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
!!! error TS2345: Types of property 'length' are incompatible.
!!! error TS2345: Type '5' is not assignable to type '3'.
a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
a10([1, 2, 3, false, true]); // Parameter type is any[]
a10([1, 2]); // Parameter type is any[]
a11([1, 2]); // Parameter type is number[]
// Rest parameter with generic
function foo<T>(...a: T[]) { }
foo<number|string>("hello", 1, 2);
foo("hello", "world");
enum E { a, b }
const enum E1 { a, b }
function foo1<T extends Number>(...a: T[]) { }
foo1(1, 2, 3, E.a);
foo1(1, 2, 3, E1.a, E.b);

Просмотреть файл

@ -96,11 +96,11 @@ a1(...array);
a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
>a9([1, 2, [["string"]], false, true]) : void
>a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void
>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean]
>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[]
>1 : 1
>2 : 2
>[["string"]] : [[string]]
>["string"] : [string]
>[["string"]] : string[][]
>["string"] : string[]
>"string" : "string"
>false : false
>true : true

Просмотреть файл

@ -0,0 +1,55 @@
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts(26,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
Types of property 'length' are incompatible.
Type '5' is not assignable to type '3'.
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5iterable.ts (1 errors) ====
// If the parameter is a rest parameter, the parameter type is any[]
// A type annotation for a rest parameter must denote an array type.
// RestParameter:
// ... Identifier TypeAnnotation(opt)
type arrayString = Array<String>
type someArray = Array<String> | number[];
type stringOrNumArray = Array<String|Number>;
function a1(...x: (number|string)[]) { }
function a2(...a) { }
function a3(...a: Array<String>) { }
function a4(...a: arrayString) { }
function a5(...a: stringOrNumArray) { }
function a9([a, b, [[c]]]) { }
function a10([a, b, [[c]], ...x]) { }
function a11([a, b, c, ...x]: number[]) { }
var array = [1, 2, 3];
var array2 = [true, false, "hello"];
a2([...array]);
a1(...array);
a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
!!! error TS2345: Types of property 'length' are incompatible.
!!! error TS2345: Type '5' is not assignable to type '3'.
a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
a10([1, 2, 3, false, true]); // Parameter type is any[]
a10([1, 2]); // Parameter type is any[]
a11([1, 2]); // Parameter type is number[]
// Rest parameter with generic
function foo<T>(...a: T[]) { }
foo<number|string>("hello", 1, 2);
foo("hello", "world");
enum E { a, b }
const enum E1 { a, b }
function foo1<T extends Number>(...a: T[]) { }
foo1(1, 2, 3, E.a);
foo1(1, 2, 3, E1.a, E.b);

Просмотреть файл

@ -96,11 +96,11 @@ a1(...array);
a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
>a9([1, 2, [["string"]], false, true]) : void
>a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void
>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean]
>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[]
>1 : 1
>2 : 2
>[["string"]] : [[string]]
>["string"] : [string]
>[["string"]] : string[][]
>["string"] : string[]
>"string" : "string"
>false : false
>true : true

Просмотреть файл

@ -0,0 +1,55 @@
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts(26,4): error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
Types of property 'length' are incompatible.
Type '5' is not assignable to type '3'.
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts (1 errors) ====
// If the parameter is a rest parameter, the parameter type is any[]
// A type annotation for a rest parameter must denote an array type.
// RestParameter:
// ... Identifier TypeAnnotation(opt)
type arrayString = Array<String>
type someArray = Array<String> | number[];
type stringOrNumArray = Array<String|Number>;
function a1(...x: (number|string)[]) { }
function a2(...a) { }
function a3(...a: Array<String>) { }
function a4(...a: arrayString) { }
function a5(...a: stringOrNumArray) { }
function a9([a, b, [[c]]]) { }
function a10([a, b, [[c]], ...x]) { }
function a11([a, b, c, ...x]: number[]) { }
var array = [1, 2, 3];
var array2 = [true, false, "hello"];
a2([...array]);
a1(...array);
a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, [[string]], boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
!!! error TS2345: Types of property 'length' are incompatible.
!!! error TS2345: Type '5' is not assignable to type '3'.
a10([1, 2, [["string"]], false, true]); // Parameter type is any[]
a10([1, 2, 3, false, true]); // Parameter type is any[]
a10([1, 2]); // Parameter type is any[]
a11([1, 2]); // Parameter type is number[]
// Rest parameter with generic
function foo<T>(...a: T[]) { }
foo<number|string>("hello", 1, 2);
foo("hello", "world");
enum E { a, b }
const enum E1 { a, b }
function foo1<T extends Number>(...a: T[]) { }
foo1(1, 2, 3, E.a);
foo1(1, 2, 3, E1.a, E.b);

Просмотреть файл

@ -96,11 +96,11 @@ a1(...array);
a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]]
>a9([1, 2, [["string"]], false, true]) : void
>a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void
>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean]
>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[]
>1 : 1
>2 : 2
>[["string"]] : [[string]]
>["string"] : [string]
>[["string"]] : string[][]
>["string"] : string[]
>"string" : "string"
>false : false
>true : true

Просмотреть файл

@ -1,8 +1,6 @@
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(12,1): error TS2322: Type '[string, number, boolean, boolean]' is not assignable to type '[string, number]'.
Types of property 'pop' are incompatible.
Type '() => string | number | boolean' is not assignable to type '() => string | number'.
Type 'string | number | boolean' is not assignable to type 'string | number'.
Type 'true' is not assignable to type 'string | number'.
Types of property 'length' are incompatible.
Type '4' is not assignable to type '2'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(14,1): error TS2322: Type '{ a: string; }' is not assignable to type 'string | number'.
Type '{ a: string; }' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(22,1): error TS2322: Type '[number, string]' is not assignable to type '[string, number]'.
@ -28,10 +26,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup
i1.tuple1 = ["foo", 5, false, true];
~~~~~~~~~
!!! error TS2322: Type '[string, number, boolean, boolean]' is not assignable to type '[string, number]'.
!!! error TS2322: Types of property 'pop' are incompatible.
!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => string | number'.
!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'string | number'.
!!! error TS2322: Type 'true' is not assignable to type 'string | number'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '4' is not assignable to type '2'.
var e3 = i1.tuple1[2]; // {}
i1.tuple1[3] = { a: "string" };
~~~~~~~~~~~~

Просмотреть файл

@ -40,12 +40,12 @@ type Strange<T> = string; // Type parameter not used
var s: Strange<number>;
s = "hello";
interface Tuple<A, B> {
interface AB<A, B> {
a: A;
b: B;
}
type Pair<T> = Tuple<T, T>;
type Pair<T> = AB<T, T>;
interface TaggedPair<T> extends Pair<T> {
tag: string;

Просмотреть файл

@ -124,29 +124,29 @@ var s: Strange<number>;
s = "hello";
>s : Symbol(s, Decl(genericTypeAliases.ts, 38, 3))
interface Tuple<A, B> {
>Tuple : Symbol(Tuple, Decl(genericTypeAliases.ts, 39, 12))
>A : Symbol(A, Decl(genericTypeAliases.ts, 41, 16))
>B : Symbol(B, Decl(genericTypeAliases.ts, 41, 18))
interface AB<A, B> {
>AB : Symbol(AB, Decl(genericTypeAliases.ts, 39, 12))
>A : Symbol(A, Decl(genericTypeAliases.ts, 41, 13))
>B : Symbol(B, Decl(genericTypeAliases.ts, 41, 15))
a: A;
>a : Symbol(Tuple.a, Decl(genericTypeAliases.ts, 41, 23))
>A : Symbol(A, Decl(genericTypeAliases.ts, 41, 16))
>a : Symbol(AB.a, Decl(genericTypeAliases.ts, 41, 20))
>A : Symbol(A, Decl(genericTypeAliases.ts, 41, 13))
b: B;
>b : Symbol(Tuple.b, Decl(genericTypeAliases.ts, 42, 9))
>B : Symbol(B, Decl(genericTypeAliases.ts, 41, 18))
>b : Symbol(AB.b, Decl(genericTypeAliases.ts, 42, 9))
>B : Symbol(B, Decl(genericTypeAliases.ts, 41, 15))
}
type Pair<T> = Tuple<T, T>;
type Pair<T> = AB<T, T>;
>Pair : Symbol(Pair, Decl(genericTypeAliases.ts, 44, 1))
>T : Symbol(T, Decl(genericTypeAliases.ts, 46, 10))
>Tuple : Symbol(Tuple, Decl(genericTypeAliases.ts, 39, 12))
>AB : Symbol(AB, Decl(genericTypeAliases.ts, 39, 12))
>T : Symbol(T, Decl(genericTypeAliases.ts, 46, 10))
>T : Symbol(T, Decl(genericTypeAliases.ts, 46, 10))
interface TaggedPair<T> extends Pair<T> {
>TaggedPair : Symbol(TaggedPair, Decl(genericTypeAliases.ts, 46, 27))
>TaggedPair : Symbol(TaggedPair, Decl(genericTypeAliases.ts, 46, 24))
>T : Symbol(T, Decl(genericTypeAliases.ts, 48, 21))
>Pair : Symbol(Pair, Decl(genericTypeAliases.ts, 44, 1))
>T : Symbol(T, Decl(genericTypeAliases.ts, 48, 21))
@ -157,17 +157,17 @@ interface TaggedPair<T> extends Pair<T> {
var p: TaggedPair<number>;
>p : Symbol(p, Decl(genericTypeAliases.ts, 52, 3))
>TaggedPair : Symbol(TaggedPair, Decl(genericTypeAliases.ts, 46, 27))
>TaggedPair : Symbol(TaggedPair, Decl(genericTypeAliases.ts, 46, 24))
p.a = 1;
>p.a : Symbol(Tuple.a, Decl(genericTypeAliases.ts, 41, 23))
>p.a : Symbol(AB.a, Decl(genericTypeAliases.ts, 41, 20))
>p : Symbol(p, Decl(genericTypeAliases.ts, 52, 3))
>a : Symbol(Tuple.a, Decl(genericTypeAliases.ts, 41, 23))
>a : Symbol(AB.a, Decl(genericTypeAliases.ts, 41, 20))
p.b = 2;
>p.b : Symbol(Tuple.b, Decl(genericTypeAliases.ts, 42, 9))
>p.b : Symbol(AB.b, Decl(genericTypeAliases.ts, 42, 9))
>p : Symbol(p, Decl(genericTypeAliases.ts, 52, 3))
>b : Symbol(Tuple.b, Decl(genericTypeAliases.ts, 42, 9))
>b : Symbol(AB.b, Decl(genericTypeAliases.ts, 42, 9))
p.tag = "test";
>p.tag : Symbol(TaggedPair.tag, Decl(genericTypeAliases.ts, 48, 41))

Просмотреть файл

@ -158,8 +158,8 @@ s = "hello";
>s : string
>"hello" : "hello"
interface Tuple<A, B> {
>Tuple : Tuple<A, B>
interface AB<A, B> {
>AB : AB<A, B>
>A : A
>B : B
@ -172,17 +172,17 @@ interface Tuple<A, B> {
>B : B
}
type Pair<T> = Tuple<T, T>;
>Pair : Tuple<T, T>
type Pair<T> = AB<T, T>;
>Pair : AB<T, T>
>T : T
>Tuple : Tuple<A, B>
>AB : AB<A, B>
>T : T
>T : T
interface TaggedPair<T> extends Pair<T> {
>TaggedPair : TaggedPair<T>
>T : T
>Pair : Tuple<T, T>
>Pair : AB<T, T>
>T : T
tag: string;

Просмотреть файл

@ -352,8 +352,8 @@ function f12(t: [Shape, boolean]) {
>Shape : Shape
let len = getProperty(t, "length");
>len : number
>getProperty(t, "length") : number
>len : 2
>getProperty(t, "length") : 2
>getProperty : <T, K extends keyof T>(obj: T, key: K) => T[K]
>t : [Shape, boolean]
>"length" : "length"

Просмотреть файл

@ -1,20 +1,20 @@
//// [nominalSubtypeCheckOfTypeParameter.ts]
interface Tuple<T, S> {
interface BinaryTuple<T, S> {
first: T
second: S
second: S
}
interface Sequence<T> {
hasNext(): boolean
pop(): T
zip<S>(seq: Sequence<S>): Sequence<Tuple<T, S>>
pop(): T
zip<S>(seq: Sequence<S>): Sequence<BinaryTuple<T, S>>
}
// error, despite the fact that the code explicitly says List<T> extends Sequence<T>, the current rules for infinitely expanding type references
// perform nominal subtyping checks that allow variance for type arguments, but not nominal subtyping for the generic type itself
interface List<T> extends Sequence<T> {
getLength(): number
zip<S>(seq: Sequence<S>): List<Tuple<T, S>>
zip<S>(seq: Sequence<S>): List<BinaryTuple<T, S>>
}

Просмотреть файл

@ -1,16 +1,16 @@
=== tests/cases/conformance/types/typeRelationships/recursiveTypes/nominalSubtypeCheckOfTypeParameter.ts ===
interface Tuple<T, S> {
>Tuple : Symbol(Tuple, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 0))
>T : Symbol(T, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 16))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 18))
interface BinaryTuple<T, S> {
>BinaryTuple : Symbol(BinaryTuple, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 0))
>T : Symbol(T, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 22))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 24))
first: T
>first : Symbol(Tuple.first, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 23))
>T : Symbol(T, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 16))
>first : Symbol(BinaryTuple.first, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 29))
>T : Symbol(T, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 22))
second: S
>second : Symbol(Tuple.second, Decl(nominalSubtypeCheckOfTypeParameter.ts, 1, 12))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 18))
second: S
>second : Symbol(BinaryTuple.second, Decl(nominalSubtypeCheckOfTypeParameter.ts, 1, 12))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 24))
}
interface Sequence<T> {
@ -20,20 +20,20 @@ interface Sequence<T> {
hasNext(): boolean
>hasNext : Symbol(Sequence.hasNext, Decl(nominalSubtypeCheckOfTypeParameter.ts, 5, 23))
pop(): T
pop(): T
>pop : Symbol(Sequence.pop, Decl(nominalSubtypeCheckOfTypeParameter.ts, 6, 22))
>T : Symbol(T, Decl(nominalSubtypeCheckOfTypeParameter.ts, 5, 19))
zip<S>(seq: Sequence<S>): Sequence<Tuple<T, S>>
>zip : Symbol(Sequence.zip, Decl(nominalSubtypeCheckOfTypeParameter.ts, 7, 14))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 8, 10))
>seq : Symbol(seq, Decl(nominalSubtypeCheckOfTypeParameter.ts, 8, 13))
zip<S>(seq: Sequence<S>): Sequence<BinaryTuple<T, S>>
>zip : Symbol(Sequence.zip, Decl(nominalSubtypeCheckOfTypeParameter.ts, 7, 12))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 8, 8))
>seq : Symbol(seq, Decl(nominalSubtypeCheckOfTypeParameter.ts, 8, 11))
>Sequence : Symbol(Sequence, Decl(nominalSubtypeCheckOfTypeParameter.ts, 3, 1))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 8, 10))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 8, 8))
>Sequence : Symbol(Sequence, Decl(nominalSubtypeCheckOfTypeParameter.ts, 3, 1))
>Tuple : Symbol(Tuple, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 0))
>BinaryTuple : Symbol(BinaryTuple, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 0))
>T : Symbol(T, Decl(nominalSubtypeCheckOfTypeParameter.ts, 5, 19))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 8, 10))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 8, 8))
}
// error, despite the fact that the code explicitly says List<T> extends Sequence<T>, the current rules for infinitely expanding type references
@ -47,15 +47,15 @@ interface List<T> extends Sequence<T> {
getLength(): number
>getLength : Symbol(List.getLength, Decl(nominalSubtypeCheckOfTypeParameter.ts, 13, 39))
zip<S>(seq: Sequence<S>): List<Tuple<T, S>>
zip<S>(seq: Sequence<S>): List<BinaryTuple<T, S>>
>zip : Symbol(List.zip, Decl(nominalSubtypeCheckOfTypeParameter.ts, 14, 23))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 15, 10))
>seq : Symbol(seq, Decl(nominalSubtypeCheckOfTypeParameter.ts, 15, 13))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 15, 8))
>seq : Symbol(seq, Decl(nominalSubtypeCheckOfTypeParameter.ts, 15, 11))
>Sequence : Symbol(Sequence, Decl(nominalSubtypeCheckOfTypeParameter.ts, 3, 1))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 15, 10))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 15, 8))
>List : Symbol(List, Decl(nominalSubtypeCheckOfTypeParameter.ts, 9, 1))
>Tuple : Symbol(Tuple, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 0))
>BinaryTuple : Symbol(BinaryTuple, Decl(nominalSubtypeCheckOfTypeParameter.ts, 0, 0))
>T : Symbol(T, Decl(nominalSubtypeCheckOfTypeParameter.ts, 13, 15))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 15, 10))
>S : Symbol(S, Decl(nominalSubtypeCheckOfTypeParameter.ts, 15, 8))
}

Просмотреть файл

@ -1,6 +1,6 @@
=== tests/cases/conformance/types/typeRelationships/recursiveTypes/nominalSubtypeCheckOfTypeParameter.ts ===
interface Tuple<T, S> {
>Tuple : Tuple<T, S>
interface BinaryTuple<T, S> {
>BinaryTuple : BinaryTuple<T, S>
>T : T
>S : S
@ -8,7 +8,7 @@ interface Tuple<T, S> {
>first : T
>T : T
second: S
second: S
>second : S
>S : S
}
@ -20,18 +20,18 @@ interface Sequence<T> {
hasNext(): boolean
>hasNext : () => boolean
pop(): T
pop(): T
>pop : () => T
>T : T
zip<S>(seq: Sequence<S>): Sequence<Tuple<T, S>>
>zip : <S>(seq: Sequence<S>) => Sequence<Tuple<T, S>>
zip<S>(seq: Sequence<S>): Sequence<BinaryTuple<T, S>>
>zip : <S>(seq: Sequence<S>) => Sequence<BinaryTuple<T, S>>
>S : S
>seq : Sequence<S>
>Sequence : Sequence<T>
>S : S
>Sequence : Sequence<T>
>Tuple : Tuple<T, S>
>BinaryTuple : BinaryTuple<T, S>
>T : T
>S : S
}
@ -47,14 +47,14 @@ interface List<T> extends Sequence<T> {
getLength(): number
>getLength : () => number
zip<S>(seq: Sequence<S>): List<Tuple<T, S>>
>zip : <S>(seq: Sequence<S>) => List<Tuple<T, S>>
zip<S>(seq: Sequence<S>): List<BinaryTuple<T, S>>
>zip : <S>(seq: Sequence<S>) => List<BinaryTuple<T, S>>
>S : S
>seq : Sequence<S>
>Sequence : Sequence<T>
>S : S
>List : List<T>
>Tuple : Tuple<T, S>
>BinaryTuple : BinaryTuple<T, S>
>T : T
>S : S
}

Просмотреть файл

@ -1,8 +1,7 @@
tests/cases/compiler/promiseEmptyTupleNoException.ts(1,38): error TS1122: A tuple type element list cannot be empty.
tests/cases/compiler/promiseEmptyTupleNoException.ts(3,3): error TS2322: Type 'any[]' is not assignable to type '[]'.
Types of property 'pop' are incompatible.
Type '() => any' is not assignable to type '() => never'.
Type 'any' is not assignable to type 'never'.
Types of property 'length' are incompatible.
Type 'number' is not assignable to type '0'.
==== tests/cases/compiler/promiseEmptyTupleNoException.ts (2 errors) ====
@ -13,8 +12,7 @@ tests/cases/compiler/promiseEmptyTupleNoException.ts(3,3): error TS2322: Type 'a
return emails;
~~~~~~~~~~~~~~
!!! error TS2322: Type 'any[]' is not assignable to type '[]'.
!!! error TS2322: Types of property 'pop' are incompatible.
!!! error TS2322: Type '() => any' is not assignable to type '() => never'.
!!! error TS2322: Type 'any' is not assignable to type 'never'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type '0'.
}

Просмотреть файл

@ -0,0 +1,37 @@
tests/cases/conformance/types/tuple/strictTupleLength.ts(1,9): error TS1122: A tuple type element list cannot be empty.
tests/cases/conformance/types/tuple/strictTupleLength.ts(11,5): error TS2403: Subsequent variable declarations must have the same type. Variable 't1' has type '[number]' at tests/cases/conformance/types/tuple/strictTupleLength.ts 1:4, but here has type '[number, number]'.
tests/cases/conformance/types/tuple/strictTupleLength.ts(12,5): error TS2403: Subsequent variable declarations must have the same type. Variable 't2' has type '[number, number]' at tests/cases/conformance/types/tuple/strictTupleLength.ts 2:4, but here has type '[number]'.
tests/cases/conformance/types/tuple/strictTupleLength.ts(18,1): error TS2322: Type 'number[]' is not assignable to type '[number]'.
Property '0' is missing in type 'number[]'.
==== tests/cases/conformance/types/tuple/strictTupleLength.ts (4 errors) ====
var t0: [];
~~
!!! error TS1122: A tuple type element list cannot be empty.
var t1: [number];
var t2: [number, number];
var arr: number[];
var len0: 0 = t0.length;
var len1: 1 = t1.length;
var len2: 2 = t2.length;
var lena: number = arr.length;
var t1 = t2; // error
~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 't1' has type '[number]' at tests/cases/conformance/types/tuple/strictTupleLength.ts 1:4, but here has type '[number, number]'.
var t2 = t1; // error
~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 't2' has type '[number, number]' at tests/cases/conformance/types/tuple/strictTupleLength.ts 2:4, but here has type '[number]'.
type A<T extends any[]> = T['length'];
var b: A<[boolean]>;
var c: 1 = b;
t1 = arr; // error with or without strict
~~
!!! error TS2322: Type 'number[]' is not assignable to type '[number]'.
!!! error TS2322: Property '0' is missing in type 'number[]'.
arr = t1; // ok with or without strict

Просмотреть файл

@ -0,0 +1,37 @@
//// [strictTupleLength.ts]
var t0: [];
var t1: [number];
var t2: [number, number];
var arr: number[];
var len0: 0 = t0.length;
var len1: 1 = t1.length;
var len2: 2 = t2.length;
var lena: number = arr.length;
var t1 = t2; // error
var t2 = t1; // error
type A<T extends any[]> = T['length'];
var b: A<[boolean]>;
var c: 1 = b;
t1 = arr; // error with or without strict
arr = t1; // ok with or without strict
//// [strictTupleLength.js]
var t0;
var t1;
var t2;
var arr;
var len0 = t0.length;
var len1 = t1.length;
var len2 = t2.length;
var lena = arr.length;
var t1 = t2; // error
var t2 = t1; // error
var b;
var c = b;
t1 = arr; // error with or without strict
arr = t1; // ok with or without strict

Просмотреть файл

@ -0,0 +1,66 @@
=== tests/cases/conformance/types/tuple/strictTupleLength.ts ===
var t0: [];
>t0 : Symbol(t0, Decl(strictTupleLength.ts, 0, 3))
var t1: [number];
>t1 : Symbol(t1, Decl(strictTupleLength.ts, 1, 3), Decl(strictTupleLength.ts, 10, 3))
var t2: [number, number];
>t2 : Symbol(t2, Decl(strictTupleLength.ts, 2, 3), Decl(strictTupleLength.ts, 11, 3))
var arr: number[];
>arr : Symbol(arr, Decl(strictTupleLength.ts, 3, 3))
var len0: 0 = t0.length;
>len0 : Symbol(len0, Decl(strictTupleLength.ts, 5, 3))
>t0.length : Symbol(length)
>t0 : Symbol(t0, Decl(strictTupleLength.ts, 0, 3))
>length : Symbol(length)
var len1: 1 = t1.length;
>len1 : Symbol(len1, Decl(strictTupleLength.ts, 6, 3))
>t1.length : Symbol(length)
>t1 : Symbol(t1, Decl(strictTupleLength.ts, 1, 3), Decl(strictTupleLength.ts, 10, 3))
>length : Symbol(length)
var len2: 2 = t2.length;
>len2 : Symbol(len2, Decl(strictTupleLength.ts, 7, 3))
>t2.length : Symbol(length)
>t2 : Symbol(t2, Decl(strictTupleLength.ts, 2, 3), Decl(strictTupleLength.ts, 11, 3))
>length : Symbol(length)
var lena: number = arr.length;
>lena : Symbol(lena, Decl(strictTupleLength.ts, 8, 3))
>arr.length : Symbol(Array.length, Decl(lib.d.ts, --, --))
>arr : Symbol(arr, Decl(strictTupleLength.ts, 3, 3))
>length : Symbol(Array.length, Decl(lib.d.ts, --, --))
var t1 = t2; // error
>t1 : Symbol(t1, Decl(strictTupleLength.ts, 1, 3), Decl(strictTupleLength.ts, 10, 3))
>t2 : Symbol(t2, Decl(strictTupleLength.ts, 2, 3), Decl(strictTupleLength.ts, 11, 3))
var t2 = t1; // error
>t2 : Symbol(t2, Decl(strictTupleLength.ts, 2, 3), Decl(strictTupleLength.ts, 11, 3))
>t1 : Symbol(t1, Decl(strictTupleLength.ts, 1, 3), Decl(strictTupleLength.ts, 10, 3))
type A<T extends any[]> = T['length'];
>A : Symbol(A, Decl(strictTupleLength.ts, 11, 12))
>T : Symbol(T, Decl(strictTupleLength.ts, 13, 7))
>T : Symbol(T, Decl(strictTupleLength.ts, 13, 7))
var b: A<[boolean]>;
>b : Symbol(b, Decl(strictTupleLength.ts, 14, 3))
>A : Symbol(A, Decl(strictTupleLength.ts, 11, 12))
var c: 1 = b;
>c : Symbol(c, Decl(strictTupleLength.ts, 15, 3))
>b : Symbol(b, Decl(strictTupleLength.ts, 14, 3))
t1 = arr; // error with or without strict
>t1 : Symbol(t1, Decl(strictTupleLength.ts, 1, 3), Decl(strictTupleLength.ts, 10, 3))
>arr : Symbol(arr, Decl(strictTupleLength.ts, 3, 3))
arr = t1; // ok with or without strict
>arr : Symbol(arr, Decl(strictTupleLength.ts, 3, 3))
>t1 : Symbol(t1, Decl(strictTupleLength.ts, 1, 3), Decl(strictTupleLength.ts, 10, 3))

Просмотреть файл

@ -0,0 +1,68 @@
=== tests/cases/conformance/types/tuple/strictTupleLength.ts ===
var t0: [];
>t0 : []
var t1: [number];
>t1 : [number]
var t2: [number, number];
>t2 : [number, number]
var arr: number[];
>arr : number[]
var len0: 0 = t0.length;
>len0 : 0
>t0.length : 0
>t0 : []
>length : 0
var len1: 1 = t1.length;
>len1 : 1
>t1.length : 1
>t1 : [number]
>length : 1
var len2: 2 = t2.length;
>len2 : 2
>t2.length : 2
>t2 : [number, number]
>length : 2
var lena: number = arr.length;
>lena : number
>arr.length : number
>arr : number[]
>length : number
var t1 = t2; // error
>t1 : [number]
>t2 : [number, number]
var t2 = t1; // error
>t2 : [number, number]
>t1 : [number]
type A<T extends any[]> = T['length'];
>A : T["length"]
>T : T
>T : T
var b: A<[boolean]>;
>b : 1
>A : T["length"]
var c: 1 = b;
>c : 1
>b : 1
t1 = arr; // error with or without strict
>t1 = arr : number[]
>t1 : [number]
>arr : number[]
arr = t1; // ok with or without strict
>arr = t1 : [number]
>arr : number[]
>t1 : [number]

Просмотреть файл

@ -0,0 +1,2 @@
x;
//# sourceMappingURL=input.js.map

Просмотреть файл

@ -0,0 +1,2 @@
x;
//# sourceMappingURL=input.js.map

Просмотреть файл

@ -5,6 +5,9 @@ tests/cases/compiler/tupleTypes.ts(15,1): error TS2322: Type '[number]' is not a
Property '1' is missing in type '[number]'.
tests/cases/compiler/tupleTypes.ts(17,1): error TS2322: Type '[string, number]' is not assignable to type '[number, string]'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/tupleTypes.ts(18,1): error TS2322: Type '[number, string, number]' is not assignable to type '[number, string]'.
Types of property 'length' are incompatible.
Type '3' is not assignable to type '2'.
tests/cases/compiler/tupleTypes.ts(41,1): error TS2322: Type 'undefined[]' is not assignable to type '[number, string]'.
tests/cases/compiler/tupleTypes.ts(47,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]'.
Types of property 'pop' are incompatible.
@ -22,7 +25,7 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n
Type '{}' is not assignable to type 'string'.
==== tests/cases/compiler/tupleTypes.ts (9 errors) ====
==== tests/cases/compiler/tupleTypes.ts (10 errors) ====
var v1: []; // Error
~~
!!! error TS1122: A tuple type element list cannot be empty.
@ -51,7 +54,11 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n
~
!!! error TS2322: Type '[string, number]' is not assignable to type '[number, string]'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
t = [1, "hello", 2]; // Ok
t = [1, "hello", 2]; // Error
~
!!! error TS2322: Type '[number, string, number]' is not assignable to type '[number, string]'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '3' is not assignable to type '2'.
var tf: [string, (x: string) => number] = ["hello", x => x.length];

Просмотреть файл

@ -16,7 +16,7 @@ t = []; // Error
t = [1]; // Error
t = [1, "hello"]; // Ok
t = ["hello", 1]; // Error
t = [1, "hello", 2]; // Ok
t = [1, "hello", 2]; // Error
var tf: [string, (x: string) => number] = ["hello", x => x.length];
@ -70,7 +70,7 @@ t = []; // Error
t = [1]; // Error
t = [1, "hello"]; // Ok
t = ["hello", 1]; // Error
t = [1, "hello", 2]; // Ok
t = [1, "hello", 2]; // Error
var tf = ["hello", function (x) { return x.length; }];
var ff1 = ff("hello", ["foo", function (x) { return x.length; }]);
var ff1;

Просмотреть файл

@ -49,7 +49,7 @@ t = [1, "hello"]; // Ok
t = ["hello", 1]; // Error
>t : Symbol(t, Decl(tupleTypes.ts, 5, 3))
t = [1, "hello", 2]; // Ok
t = [1, "hello", 2]; // Error
>t : Symbol(t, Decl(tupleTypes.ts, 5, 3))
var tf: [string, (x: string) => number] = ["hello", x => x.length];

Просмотреть файл

@ -66,7 +66,7 @@ t = ["hello", 1]; // Error
>"hello" : "hello"
>1 : 1
t = [1, "hello", 2]; // Ok
t = [1, "hello", 2]; // Error
>t = [1, "hello", 2] : [number, string, number]
>t : [number, string]
>[1, "hello", 2] : [number, string, number]

Просмотреть файл

@ -0,0 +1,33 @@
tests/cases/conformance/types/union/unionTypeFromArrayLiteral.ts(9,5): error TS2322: Type '[number, string, string]' is not assignable to type '[number, string]'.
Types of property 'length' are incompatible.
Type '3' is not assignable to type '2'.
==== tests/cases/conformance/types/union/unionTypeFromArrayLiteral.ts (1 errors) ====
// The resulting type an array literal expression is determined as follows:
// If the array literal is empty, the resulting type is an array type with the element type Undefined.
// Otherwise, if the array literal is contextually typed by a type that has a property with the numeric name 0, the resulting type is a tuple type constructed from the types of the element expressions.
// Otherwise, the resulting type is an array type with an element type that is the union of the types of the element expressions.
var arr1 = [1, 2]; // number[]
var arr2 = ["hello", true]; // (string | number)[]
var arr3Tuple: [number, string] = [3, "three"]; // [number, string]
var arr4Tuple: [number, string] = [3, "three", "hello"]; // [number, string, string]
~~~~~~~~~
!!! error TS2322: Type '[number, string, string]' is not assignable to type '[number, string]'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '3' is not assignable to type '2'.
var arrEmpty = [];
var arr5Tuple: {
0: string;
5: number;
} = ["hello", true, false, " hello", true, 10, "any"]; // Tuple
class C { foo() { } }
class D { foo2() { } }
class E extends C { foo3() { } }
class F extends C { foo4() { } }
var c: C, d: D, e: E, f: F;
var arr6 = [c, d]; // (C | D)[]
var arr7 = [c, d, e]; // (C | D)[]
var arr8 = [c, e]; // C[]
var arr9 = [e, f]; // (E|F)[]

Просмотреть файл

@ -1,9 +1,16 @@
tests/cases/conformance/types/tuple/wideningTuples3.ts(3,5): error TS7005: Variable 'b' implicitly has an '[any, any]' type.
tests/cases/conformance/types/tuple/wideningTuples3.ts(3,9): error TS2322: Type '[undefined, null]' is not assignable to type '[any]'.
Types of property 'length' are incompatible.
Type '2' is not assignable to type '1'.
==== tests/cases/conformance/types/tuple/wideningTuples3.ts (1 errors) ====
==== tests/cases/conformance/types/tuple/wideningTuples3.ts (2 errors) ====
var a: [any];
var b = a = [undefined, null];
~
!!! error TS7005: Variable 'b' implicitly has an '[any, any]' type.
!!! error TS7005: Variable 'b' implicitly has an '[any, any]' type.
~
!!! error TS2322: Type '[undefined, null]' is not assignable to type '[any]'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '2' is not assignable to type '1'.

Просмотреть файл

@ -0,0 +1,14 @@
tests/cases/conformance/types/tuple/wideningTuples4.ts(3,9): error TS2322: Type '[undefined, null]' is not assignable to type '[any]'.
Types of property 'length' are incompatible.
Type '2' is not assignable to type '1'.
==== tests/cases/conformance/types/tuple/wideningTuples4.ts (1 errors) ====
var a: [any];
var b = a = [undefined, null];
~
!!! error TS2322: Type '[undefined, null]' is not assignable to type '[any]'.
!!! error TS2322: Types of property 'length' are incompatible.
!!! error TS2322: Type '2' is not assignable to type '1'.
b = ["", ""];

Просмотреть файл

@ -15,7 +15,7 @@ t = []; // Error
t = [1]; // Error
t = [1, "hello"]; // Ok
t = ["hello", 1]; // Error
t = [1, "hello", 2]; // Ok
t = [1, "hello", 2]; // Error
var tf: [string, (x: string) => number] = ["hello", x => x.length];

Просмотреть файл

@ -1,6 +1,7 @@
interface StrNum extends Array<string|number> {
0: string;
1: number;
length: 2;
}
var x: [string, number];
@ -8,6 +9,7 @@ var y: StrNum
var z: {
0: string;
1: number;
length: 2;
}
var [a, b, c] = x;

Просмотреть файл

@ -11,6 +11,8 @@ enum E2 { one }
var numStrTuple: [number, string] = [5, "foo"];
var emptyObjTuple = <[{}, {}]>numStrTuple;
var numStrBoolTuple = <[number, string, boolean]>numStrTuple;
var shorter = numStrBoolTuple as [number, string]
var longer = numStrTuple as [number, string, boolean]
var classCDTuple: [C, D] = [new C(), new D()];
var interfaceIITuple = <[I, I]>classCDTuple;
var classCDATuple = <[C, D, A]>classCDTuple;

Просмотреть файл

@ -0,0 +1,19 @@
var t0: [];
var t1: [number];
var t2: [number, number];
var arr: number[];
var len0: 0 = t0.length;
var len1: 1 = t1.length;
var len2: 2 = t2.length;
var lena: number = arr.length;
var t1 = t2; // error
var t2 = t1; // error
type A<T extends any[]> = T['length'];
var b: A<[boolean]>;
var c: 1 = b;
t1 = arr; // error with or without strict
arr = t1; // ok with or without strict

Просмотреть файл

@ -39,12 +39,12 @@ type Strange<T> = string; // Type parameter not used
var s: Strange<number>;
s = "hello";
interface Tuple<A, B> {
interface AB<A, B> {
a: A;
b: B;
}
type Pair<T> = Tuple<T, T>;
type Pair<T> = AB<T, T>;
interface TaggedPair<T> extends Pair<T> {
tag: string;

Просмотреть файл

@ -1,17 +1,17 @@
interface Tuple<T, S> {
interface BinaryTuple<T, S> {
first: T
second: S
second: S
}
interface Sequence<T> {
hasNext(): boolean
pop(): T
zip<S>(seq: Sequence<S>): Sequence<Tuple<T, S>>
pop(): T
zip<S>(seq: Sequence<S>): Sequence<BinaryTuple<T, S>>
}
// error, despite the fact that the code explicitly says List<T> extends Sequence<T>, the current rules for infinitely expanding type references
// perform nominal subtyping checks that allow variance for type arguments, but not nominal subtyping for the generic type itself
interface List<T> extends Sequence<T> {
getLength(): number
zip<S>(seq: Sequence<S>): List<Tuple<T, S>>
zip<S>(seq: Sequence<S>): List<BinaryTuple<T, S>>
}