diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cb373b4375f..38bc617c650 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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 = createObjectType(ObjectFlags.Tuple | ObjectFlags.Reference); type.typeParameters = typeParameters; type.outerTypeParameters = undefined; diff --git a/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt b/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt index 5a367a4122f..4d6fbd063ae 100644 --- a/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt +++ b/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt @@ -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 { 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; diff --git a/tests/baselines/reference/arityAndOrderCompatibility01.js b/tests/baselines/reference/arityAndOrderCompatibility01.js index 2eb1bcf8bd8..bf7736a80c9 100644 --- a/tests/baselines/reference/arityAndOrderCompatibility01.js +++ b/tests/baselines/reference/arityAndOrderCompatibility01.js @@ -2,6 +2,7 @@ interface StrNum extends Array { 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; diff --git a/tests/baselines/reference/arityAndOrderCompatibility01.symbols b/tests/baselines/reference/arityAndOrderCompatibility01.symbols index c6ef08a845b..3a5d55dc1e6 100644 --- a/tests/baselines/reference/arityAndOrderCompatibility01.symbols +++ b/tests/baselines/reference/arityAndOrderCompatibility01.symbols @@ -5,109 +5,113 @@ interface StrNum extends Array { 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)) diff --git a/tests/baselines/reference/arityAndOrderCompatibility01.types b/tests/baselines/reference/arityAndOrderCompatibility01.types index 934c5c6966d..80e91fbd2e7 100644 --- a/tests/baselines/reference/arityAndOrderCompatibility01.types +++ b/tests/baselines/reference/arityAndOrderCompatibility01.types @@ -5,6 +5,8 @@ interface StrNum extends Array { 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] diff --git a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt index 3e9777aea7c..8cb36b113a7 100644 --- a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt +++ b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt @@ -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. diff --git a/tests/baselines/reference/arrayLiterals3.errors.txt b/tests/baselines/reference/arrayLiterals3.errors.txt index 3ebf4174f51..8c36d7d59c1 100644 --- a/tests/baselines/reference/arrayLiterals3.errors.txt +++ b/tests/baselines/reference/arrayLiterals3.errors.txt @@ -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 diff --git a/tests/baselines/reference/castingTuple.errors.txt b/tests/baselines/reference/castingTuple.errors.txt index eb6aac5f463..a17f8c2b082 100644 --- a/tests/baselines/reference/castingTuple.errors.txt +++ b/tests/baselines/reference/castingTuple.errors.txt @@ -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 = 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'. diff --git a/tests/baselines/reference/castingTuple.js b/tests/baselines/reference/castingTuple.js index 3744d40d8a5..a94246a19b8 100644 --- a/tests/baselines/reference/castingTuple.js +++ b/tests/baselines/reference/castingTuple.js @@ -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; diff --git a/tests/baselines/reference/castingTuple.symbols b/tests/baselines/reference/castingTuple.symbols index 61edfb4b376..3cf5face2a6 100644 --- a/tests/baselines/reference/castingTuple.symbols +++ b/tests/baselines/reference/castingTuple.symbols @@ -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 = 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; diff --git a/tests/baselines/reference/castingTuple.types b/tests/baselines/reference/castingTuple.types index 23d2e51a576..0b9aa0a1487 100644 --- a/tests/baselines/reference/castingTuple.types +++ b/tests/baselines/reference/castingTuple.types @@ -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 diff --git a/tests/baselines/reference/contextualTypeWithTuple.errors.txt b/tests/baselines/reference/contextualTypeWithTuple.errors.txt index a488d8c7648..58a90919c5b 100644 --- a/tests/baselines/reference/contextualTypeWithTuple.errors.txt +++ b/tests/baselines/reference/contextualTypeWithTuple.errors.txt @@ -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]'. diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1ES5.errors.txt index 8e51c2b6111..fbbfc3b0d21 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5.errors.txt @@ -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. diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types index a4b7e882298..c7a5c44f1d4 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types @@ -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 diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.errors.txt index 101a37fc84a..1dc3c61bb3a 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.errors.txt @@ -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. diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types index 9d72faf55b6..b41a2027586 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types @@ -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 diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt index e900b9be393..f6c17a5c0ea 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt @@ -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 (?) diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types index b997dcf6017..9de904efdec 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types @@ -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 diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt index 81c85f7c42b..96b93423660 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -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 diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration3ES5.errors.txt new file mode 100644 index 00000000000..3b16993a047 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.errors.txt @@ -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 + type someArray = Array | number[]; + type stringOrNumArray = Array; + + function a1(...x: (number|string)[]) { } + function a2(...a) { } + function a3(...a: Array) { } + 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(...a: T[]) { } + foo("hello", 1, 2); + foo("hello", "world"); + + enum E { a, b } + const enum E1 { a, b } + function foo1(...a: T[]) { } + foo1(1, 2, 3, E.a); + foo1(1, 2, 3, E1.a, E.b); + + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types index a91d54d5284..33e0d3b6bd8 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types @@ -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 diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.errors.txt new file mode 100644 index 00000000000..f0dbf325ed4 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.errors.txt @@ -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 + type someArray = Array | number[]; + type stringOrNumArray = Array; + + function a1(...x: (number|string)[]) { } + function a2(...a) { } + function a3(...a: Array) { } + 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(...a: T[]) { } + foo("hello", 1, 2); + foo("hello", "world"); + + enum E { a, b } + const enum E1 { a, b } + function foo1(...a: T[]) { } + foo1(1, 2, 3, E.a); + foo1(1, 2, 3, E1.a, E.b); + + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types index 5f2963abe87..931e149ffe2 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5iterable.types @@ -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 diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration3ES6.errors.txt new file mode 100644 index 00000000000..67a5c1bf87f --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.errors.txt @@ -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 + type someArray = Array | number[]; + type stringOrNumArray = Array; + + function a1(...x: (number|string)[]) { } + function a2(...a) { } + function a3(...a: Array) { } + 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(...a: T[]) { } + foo("hello", 1, 2); + foo("hello", "world"); + + enum E { a, b } + const enum E1 { a, b } + function foo1(...a: T[]) { } + foo1(1, 2, 3, E.a); + foo1(1, 2, 3, E1.a, E.b); + + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types index 397ec934a2f..dc5e64d2c2c 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types @@ -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 diff --git a/tests/baselines/reference/genericCallWithTupleType.errors.txt b/tests/baselines/reference/genericCallWithTupleType.errors.txt index 617c4f7159b..65920596c45 100644 --- a/tests/baselines/reference/genericCallWithTupleType.errors.txt +++ b/tests/baselines/reference/genericCallWithTupleType.errors.txt @@ -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" }; ~~~~~~~~~~~~ diff --git a/tests/baselines/reference/genericTypeAliases.js b/tests/baselines/reference/genericTypeAliases.js index 8218f5c886c..282fd9868a9 100644 --- a/tests/baselines/reference/genericTypeAliases.js +++ b/tests/baselines/reference/genericTypeAliases.js @@ -40,12 +40,12 @@ type Strange = string; // Type parameter not used var s: Strange; s = "hello"; -interface Tuple { +interface AB { a: A; b: B; } -type Pair = Tuple; +type Pair = AB; interface TaggedPair extends Pair { tag: string; diff --git a/tests/baselines/reference/genericTypeAliases.symbols b/tests/baselines/reference/genericTypeAliases.symbols index d5f68ec0615..521afe800b3 100644 --- a/tests/baselines/reference/genericTypeAliases.symbols +++ b/tests/baselines/reference/genericTypeAliases.symbols @@ -124,29 +124,29 @@ var s: Strange; s = "hello"; >s : Symbol(s, Decl(genericTypeAliases.ts, 38, 3)) -interface Tuple { ->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 { +>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 = Tuple; +type Pair = AB; >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 extends Pair { ->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 extends Pair { var p: TaggedPair; >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)) diff --git a/tests/baselines/reference/genericTypeAliases.types b/tests/baselines/reference/genericTypeAliases.types index b4c75841245..722347b0f72 100644 --- a/tests/baselines/reference/genericTypeAliases.types +++ b/tests/baselines/reference/genericTypeAliases.types @@ -158,8 +158,8 @@ s = "hello"; >s : string >"hello" : "hello" -interface Tuple { ->Tuple : Tuple +interface AB { +>AB : AB >A : A >B : B @@ -172,17 +172,17 @@ interface Tuple { >B : B } -type Pair = Tuple; ->Pair : Tuple +type Pair = AB; +>Pair : AB >T : T ->Tuple : Tuple +>AB : AB >T : T >T : T interface TaggedPair extends Pair { >TaggedPair : TaggedPair >T : T ->Pair : Tuple +>Pair : AB >T : T tag: string; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index 9ae7b793ce2..302cefabf90 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -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 : (obj: T, key: K) => T[K] >t : [Shape, boolean] >"length" : "length" diff --git a/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.js b/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.js index 3259b3287fa..5712fb7c244 100644 --- a/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.js +++ b/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.js @@ -1,20 +1,20 @@ //// [nominalSubtypeCheckOfTypeParameter.ts] -interface Tuple { +interface BinaryTuple { first: T - second: S + second: S } interface Sequence { hasNext(): boolean - pop(): T - zip(seq: Sequence): Sequence> + pop(): T + zip(seq: Sequence): Sequence> } // error, despite the fact that the code explicitly says List extends Sequence, 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 extends Sequence { getLength(): number - zip(seq: Sequence): List> + zip(seq: Sequence): List> } diff --git a/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.symbols b/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.symbols index c7d9a1b50f4..3d24b82aa8f 100644 --- a/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.symbols +++ b/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.symbols @@ -1,16 +1,16 @@ === tests/cases/conformance/types/typeRelationships/recursiveTypes/nominalSubtypeCheckOfTypeParameter.ts === -interface Tuple { ->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 { +>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 { @@ -20,20 +20,20 @@ interface Sequence { 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(seq: Sequence): Sequence> ->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(seq: Sequence): Sequence> +>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 extends Sequence, the current rules for infinitely expanding type references @@ -47,15 +47,15 @@ interface List extends Sequence { getLength(): number >getLength : Symbol(List.getLength, Decl(nominalSubtypeCheckOfTypeParameter.ts, 13, 39)) - zip(seq: Sequence): List> + zip(seq: Sequence): List> >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)) } diff --git a/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.types b/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.types index 79b2ac77d78..5da84d0c8a4 100644 --- a/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.types +++ b/tests/baselines/reference/nominalSubtypeCheckOfTypeParameter.types @@ -1,6 +1,6 @@ === tests/cases/conformance/types/typeRelationships/recursiveTypes/nominalSubtypeCheckOfTypeParameter.ts === -interface Tuple { ->Tuple : Tuple +interface BinaryTuple { +>BinaryTuple : BinaryTuple >T : T >S : S @@ -8,7 +8,7 @@ interface Tuple { >first : T >T : T - second: S + second: S >second : S >S : S } @@ -20,18 +20,18 @@ interface Sequence { hasNext(): boolean >hasNext : () => boolean - pop(): T + pop(): T >pop : () => T >T : T - zip(seq: Sequence): Sequence> ->zip : (seq: Sequence) => Sequence> + zip(seq: Sequence): Sequence> +>zip : (seq: Sequence) => Sequence> >S : S >seq : Sequence >Sequence : Sequence >S : S >Sequence : Sequence ->Tuple : Tuple +>BinaryTuple : BinaryTuple >T : T >S : S } @@ -47,14 +47,14 @@ interface List extends Sequence { getLength(): number >getLength : () => number - zip(seq: Sequence): List> ->zip : (seq: Sequence) => List> + zip(seq: Sequence): List> +>zip : (seq: Sequence) => List> >S : S >seq : Sequence >Sequence : Sequence >S : S >List : List ->Tuple : Tuple +>BinaryTuple : BinaryTuple >T : T >S : S } diff --git a/tests/baselines/reference/promiseEmptyTupleNoException.errors.txt b/tests/baselines/reference/promiseEmptyTupleNoException.errors.txt index 0237d658da5..73d768ddfeb 100644 --- a/tests/baselines/reference/promiseEmptyTupleNoException.errors.txt +++ b/tests/baselines/reference/promiseEmptyTupleNoException.errors.txt @@ -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'. } \ No newline at end of file diff --git a/tests/baselines/reference/strictTupleLength.errors.txt b/tests/baselines/reference/strictTupleLength.errors.txt new file mode 100644 index 00000000000..c31064f6b6b --- /dev/null +++ b/tests/baselines/reference/strictTupleLength.errors.txt @@ -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['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 + \ No newline at end of file diff --git a/tests/baselines/reference/strictTupleLength.js b/tests/baselines/reference/strictTupleLength.js new file mode 100644 index 00000000000..e4ae65f2fde --- /dev/null +++ b/tests/baselines/reference/strictTupleLength.js @@ -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['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 diff --git a/tests/baselines/reference/strictTupleLength.symbols b/tests/baselines/reference/strictTupleLength.symbols new file mode 100644 index 00000000000..e81697b84bf --- /dev/null +++ b/tests/baselines/reference/strictTupleLength.symbols @@ -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['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)) + diff --git a/tests/baselines/reference/strictTupleLength.types b/tests/baselines/reference/strictTupleLength.types new file mode 100644 index 00000000000..917c2f7db23 --- /dev/null +++ b/tests/baselines/reference/strictTupleLength.types @@ -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['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] + diff --git a/tests/baselines/reference/transpile/Supports setting strictTuples.js b/tests/baselines/reference/transpile/Supports setting strictTuples.js new file mode 100644 index 00000000000..8394371f908 --- /dev/null +++ b/tests/baselines/reference/transpile/Supports setting strictTuples.js @@ -0,0 +1,2 @@ +x; +//# sourceMappingURL=input.js.map \ No newline at end of file diff --git a/tests/baselines/reference/transpile/Supports setting strictTuples.oldTranspile.js b/tests/baselines/reference/transpile/Supports setting strictTuples.oldTranspile.js new file mode 100644 index 00000000000..8394371f908 --- /dev/null +++ b/tests/baselines/reference/transpile/Supports setting strictTuples.oldTranspile.js @@ -0,0 +1,2 @@ +x; +//# sourceMappingURL=input.js.map \ No newline at end of file diff --git a/tests/baselines/reference/tupleTypes.errors.txt b/tests/baselines/reference/tupleTypes.errors.txt index 3b55476e4b1..16a8f66ba79 100644 --- a/tests/baselines/reference/tupleTypes.errors.txt +++ b/tests/baselines/reference/tupleTypes.errors.txt @@ -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]; diff --git a/tests/baselines/reference/tupleTypes.js b/tests/baselines/reference/tupleTypes.js index 451aeb5eb09..947b7bba30b 100644 --- a/tests/baselines/reference/tupleTypes.js +++ b/tests/baselines/reference/tupleTypes.js @@ -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; diff --git a/tests/baselines/reference/tupleTypes.symbols b/tests/baselines/reference/tupleTypes.symbols index 1f14b269ca9..cf60cea8534 100644 --- a/tests/baselines/reference/tupleTypes.symbols +++ b/tests/baselines/reference/tupleTypes.symbols @@ -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]; diff --git a/tests/baselines/reference/tupleTypes.types b/tests/baselines/reference/tupleTypes.types index 3bbf48bdb29..3f68d4c7e2d 100644 --- a/tests/baselines/reference/tupleTypes.types +++ b/tests/baselines/reference/tupleTypes.types @@ -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] diff --git a/tests/baselines/reference/unionTypeFromArrayLiteral.errors.txt b/tests/baselines/reference/unionTypeFromArrayLiteral.errors.txt new file mode 100644 index 00000000000..2ecce8a802e --- /dev/null +++ b/tests/baselines/reference/unionTypeFromArrayLiteral.errors.txt @@ -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)[] \ No newline at end of file diff --git a/tests/baselines/reference/wideningTuples3.errors.txt b/tests/baselines/reference/wideningTuples3.errors.txt index 43c7e349a0c..15e02cfb559 100644 --- a/tests/baselines/reference/wideningTuples3.errors.txt +++ b/tests/baselines/reference/wideningTuples3.errors.txt @@ -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. \ No newline at end of file +!!! 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'. \ No newline at end of file diff --git a/tests/baselines/reference/wideningTuples4.errors.txt b/tests/baselines/reference/wideningTuples4.errors.txt new file mode 100644 index 00000000000..e38035e7041 --- /dev/null +++ b/tests/baselines/reference/wideningTuples4.errors.txt @@ -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 = ["", ""]; \ No newline at end of file diff --git a/tests/cases/compiler/tupleTypes.ts b/tests/cases/compiler/tupleTypes.ts index 80181f8b332..53e5b584b7a 100644 --- a/tests/cases/compiler/tupleTypes.ts +++ b/tests/cases/compiler/tupleTypes.ts @@ -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]; diff --git a/tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts b/tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts index 0f486d843ea..85a035d472b 100644 --- a/tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts +++ b/tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts @@ -1,6 +1,7 @@ interface StrNum extends Array { 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; diff --git a/tests/cases/conformance/types/tuple/castingTuple.ts b/tests/cases/conformance/types/tuple/castingTuple.ts index cf5c58af346..2ffc22ff34c 100644 --- a/tests/cases/conformance/types/tuple/castingTuple.ts +++ b/tests/cases/conformance/types/tuple/castingTuple.ts @@ -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; diff --git a/tests/cases/conformance/types/tuple/strictTupleLength.ts b/tests/cases/conformance/types/tuple/strictTupleLength.ts new file mode 100644 index 00000000000..eaa9111e557 --- /dev/null +++ b/tests/cases/conformance/types/tuple/strictTupleLength.ts @@ -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['length']; +var b: A<[boolean]>; +var c: 1 = b; + +t1 = arr; // error with or without strict +arr = t1; // ok with or without strict diff --git a/tests/cases/conformance/types/typeAliases/genericTypeAliases.ts b/tests/cases/conformance/types/typeAliases/genericTypeAliases.ts index e26279a8a41..8c8ab3291fa 100644 --- a/tests/cases/conformance/types/typeAliases/genericTypeAliases.ts +++ b/tests/cases/conformance/types/typeAliases/genericTypeAliases.ts @@ -39,12 +39,12 @@ type Strange = string; // Type parameter not used var s: Strange; s = "hello"; -interface Tuple { +interface AB { a: A; b: B; } -type Pair = Tuple; +type Pair = AB; interface TaggedPair extends Pair { tag: string; diff --git a/tests/cases/conformance/types/typeRelationships/recursiveTypes/nominalSubtypeCheckOfTypeParameter.ts b/tests/cases/conformance/types/typeRelationships/recursiveTypes/nominalSubtypeCheckOfTypeParameter.ts index ed8d724300d..ea16201ae91 100644 --- a/tests/cases/conformance/types/typeRelationships/recursiveTypes/nominalSubtypeCheckOfTypeParameter.ts +++ b/tests/cases/conformance/types/typeRelationships/recursiveTypes/nominalSubtypeCheckOfTypeParameter.ts @@ -1,17 +1,17 @@ -interface Tuple { +interface BinaryTuple { first: T - second: S + second: S } interface Sequence { hasNext(): boolean - pop(): T - zip(seq: Sequence): Sequence> + pop(): T + zip(seq: Sequence): Sequence> } // error, despite the fact that the code explicitly says List extends Sequence, 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 extends Sequence { getLength(): number - zip(seq: Sequence): List> + zip(seq: Sequence): List> }