|
| 1 | +==== tests/cases/compiler/tupleTypes.ts (9 errors) ==== |
| 2 | + var v1: []; // Error |
| 3 | + ~~ |
| 4 | +!!! Type argument list cannot be empty. |
| 5 | + var v2: [number]; |
| 6 | + var v3: [number, string]; |
| 7 | + var v4: [number, [string, string]]; |
| 8 | + |
| 9 | + var t: [number, string]; |
| 10 | + var t0 = t[0]; // number |
| 11 | + var t0: number; |
| 12 | + var t1 = t[1]; // string |
| 13 | + var t1: string; |
| 14 | + var t2 = t[2]; // {} |
| 15 | + var t2: {}; |
| 16 | + |
| 17 | + t = []; // Error |
| 18 | + ~ |
| 19 | +!!! Type '[]' is not assignable to type '[number, string]': |
| 20 | +!!! Property '0' is missing in type '[]'. |
| 21 | + t = [1]; // Error |
| 22 | + ~ |
| 23 | +!!! Type '[number]' is not assignable to type '[number, string]': |
| 24 | +!!! Property '1' is missing in type '[number]'. |
| 25 | + t = [1, "hello"]; // Ok |
| 26 | + t = ["hello", 1]; // Error |
| 27 | + ~ |
| 28 | +!!! Type '[string, number]' is not assignable to type '[number, string]': |
| 29 | +!!! Types of property '0' are incompatible: |
| 30 | +!!! Type 'string' is not assignable to type 'number'. |
| 31 | + t = [1, "hello", 2]; // Ok |
| 32 | + |
| 33 | + var tf: [string, (x: string) => number] = ["hello", x => x.length]; |
| 34 | + |
| 35 | + declare function ff<T, U>(a: T, b: [T, (x: T) => U]): U; |
| 36 | + var ff1 = ff("hello", ["foo", x => x.length]); |
| 37 | + var ff1: number; |
| 38 | + |
| 39 | + function tuple2<T0, T1>(item0: T0, item1: T1): [T0, T1]{ |
| 40 | + return [item0, item1]; |
| 41 | + } |
| 42 | + |
| 43 | + var tt = tuple2(1, "string"); |
| 44 | + var tt0 = tt[0]; |
| 45 | + var tt0: number; |
| 46 | + var tt1 = tt[1]; |
| 47 | + var tt1: string; |
| 48 | + var tt2 = tt[2]; |
| 49 | + var tt2: {}; |
| 50 | + |
| 51 | + tt = tuple2(1, undefined); |
| 52 | + tt = [1, undefined]; |
| 53 | + tt = [undefined, undefined]; |
| 54 | + tt = []; // Error |
| 55 | + ~~ |
| 56 | +!!! Type '[]' is not assignable to type '[number, string]'. |
| 57 | + |
| 58 | + var a: number[]; |
| 59 | + var a1: [number, string]; |
| 60 | + var a2: [number, number]; |
| 61 | + var a3: [number, {}]; |
| 62 | + a = a1; // Error |
| 63 | + ~ |
| 64 | +!!! Type '[number, string]' is not assignable to type 'number[]': |
| 65 | +!!! Types of property 'concat' are incompatible: |
| 66 | +!!! Type '{ <U extends {}[]>(...items: U[]): {}[]; (...items: {}[]): {}[]; }' is not assignable to type '{ <U extends number[]>(...items: U[]): number[]; (...items: number[]): number[]; }': |
| 67 | +!!! Type '{}[]' is not assignable to type 'number[]': |
| 68 | +!!! Type '{}' is not assignable to type 'number'. |
| 69 | + a = a2; |
| 70 | + a = a3; // Error |
| 71 | + ~ |
| 72 | +!!! Type '[number, {}]' is not assignable to type 'number[]': |
| 73 | +!!! Types of property 'concat' are incompatible: |
| 74 | +!!! Type '{ <U extends {}[]>(...items: U[]): {}[]; (...items: {}[]): {}[]; }' is not assignable to type '{ <U extends number[]>(...items: U[]): number[]; (...items: number[]): number[]; }': |
| 75 | +!!! Type '{}[]' is not assignable to type 'number[]': |
| 76 | +!!! Type '{}' is not assignable to type 'number'. |
| 77 | + a1 = a2; // Error |
| 78 | + ~~ |
| 79 | +!!! Type '[number, number]' is not assignable to type '[number, string]': |
| 80 | +!!! Types of property '1' are incompatible: |
| 81 | +!!! Type 'number' is not assignable to type 'string'. |
| 82 | + a1 = a3; // Error |
| 83 | + ~~ |
| 84 | +!!! Type '[number, {}]' is not assignable to type '[number, string]': |
| 85 | +!!! Types of property '1' are incompatible: |
| 86 | +!!! Type '{}' is not assignable to type 'string'. |
| 87 | + a3 = a1; |
| 88 | + a3 = a2; |
| 89 | + |
0 commit comments