Skip to content

Commit 03c06c6

Browse files
committed
Check for extended empty tuples in isTupleLikeType
1 parent 3880fce commit 03c06c6

File tree

58 files changed

+722
-720
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+722
-720
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
19491949
const emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, emptyArray) as ObjectType as GenericType;
19501950
emptyGenericType.instantiations = new Map<string, TypeReference>();
19511951

1952+
const emptyReadonlyTupleType = createTupleType(emptyArray, emptyArray, /*readonly*/ true);
1953+
19521954
const anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, emptyArray);
19531955
// The anyFunctionType contains the anyFunctionType by definition. The flag is further propagated
19541956
// in getPropagatingFlagsOfTypes, and it is checked in inferFromTypes.
@@ -22902,7 +22904,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2290222904
}
2290322905

2290422906
function isTupleLikeType(type: Type): boolean {
22905-
return isTupleType(type) || !!getPropertyOfType(type, "0" as __String);
22907+
return isTupleType(type) || !!getPropertyOfType(type, "0" as __String) || isTypeAssignableTo(type, emptyReadonlyTupleType);
2290622908
}
2290722909

2290822910
function isArrayOrTupleLikeType(type: Type): boolean {

tests/baselines/reference/anyInferenceAnonymousFunctions.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ paired.reduce(function (a1, a2) {
1919
>{} : {}
2020

2121
} , []);
22-
>[] : undefined[]
22+
>[] : []
2323

2424
paired.reduce((b1, b2) => {
2525
>paired.reduce((b1, b2) => { return b1.concat({});} , []) : any
@@ -38,7 +38,7 @@ paired.reduce((b1, b2) => {
3838
>{} : {}
3939

4040
} , []);
41-
>[] : undefined[]
41+
>[] : []
4242

4343
paired.reduce((b3, b4) => b3.concat({}), []);
4444
>paired.reduce((b3, b4) => b3.concat({}), []) : any
@@ -53,7 +53,7 @@ paired.reduce((b3, b4) => b3.concat({}), []);
5353
>b3 : any
5454
>concat : any
5555
>{} : {}
56-
>[] : undefined[]
56+
>[] : []
5757

5858
paired.map((c1) => c1.count);
5959
>paired.map((c1) => c1.count) : any[]

tests/baselines/reference/assignmentCompatability46.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/assignmentCompatability46.ts(3,4): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'never'.
1+
tests/cases/compiler/assignmentCompatability46.ts(3,4): error TS2345: Argument of type '[number, number, number]' is not assignable to parameter of type 'never'.
22
tests/cases/compiler/assignmentCompatability46.ts(4,4): error TS2345: Argument of type '{ a: number; b: number; }' is not assignable to parameter of type 'never'.
33

44

@@ -7,7 +7,7 @@ tests/cases/compiler/assignmentCompatability46.ts(4,4): error TS2345: Argument o
77

88
fn([1, 2, 3])
99
~~~~~~~~~
10-
!!! error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'never'.
10+
!!! error TS2345: Argument of type '[number, number, number]' is not assignable to parameter of type 'never'.
1111
fn({ a: 1, b: 2 })
1212
~~~~~~~~~~~~~~
1313
!!! error TS2345: Argument of type '{ a: number; b: number; }' is not assignable to parameter of type 'never'.

tests/baselines/reference/assignmentCompatability46.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare function fn(x: never): void;
66
fn([1, 2, 3])
77
>fn([1, 2, 3]) : void
88
>fn : (x: never) => void
9-
>[1, 2, 3] : number[]
9+
>[1, 2, 3] : [number, number, number]
1010
>1 : 1
1111
>2 : 2
1212
>3 : 3

tests/baselines/reference/assignmentNestedInLiterals.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ var target, x, y;
55
>y : any
66

77
target = [x = 1, y = x];
8-
>target = [x = 1, y = x] : number[]
8+
>target = [x = 1, y = x] : [number, number]
99
>target : any
10-
>[x = 1, y = x] : number[]
10+
>[x = 1, y = x] : [number, number]
1111
>x = 1 : 1
1212
>x : any
1313
>1 : 1

tests/baselines/reference/bigintWithoutLib.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bigIntArray = new BigInt64Array([1n, 2n, 3n]);
125125
>bigIntArray : BigInt64Array
126126
>new BigInt64Array([1n, 2n, 3n]) : any
127127
>BigInt64Array : any
128-
>[1n, 2n, 3n] : bigint[]
128+
>[1n, 2n, 3n] : [bigint, bigint, bigint]
129129
>1n : 1n
130130
>2n : 2n
131131
>3n : 3n
@@ -135,7 +135,7 @@ bigIntArray = new BigInt64Array([1, 2, 3]);
135135
>bigIntArray : BigInt64Array
136136
>new BigInt64Array([1, 2, 3]) : any
137137
>BigInt64Array : any
138-
>[1, 2, 3] : number[]
138+
>[1, 2, 3] : [number, number, number]
139139
>1 : 1
140140
>2 : 2
141141
>3 : 3
@@ -205,7 +205,7 @@ bigUintArray = new BigUint64Array([1n, 2n, 3n]);
205205
>bigUintArray : BigUint64Array
206206
>new BigUint64Array([1n, 2n, 3n]) : any
207207
>BigUint64Array : any
208-
>[1n, 2n, 3n] : bigint[]
208+
>[1n, 2n, 3n] : [bigint, bigint, bigint]
209209
>1n : 1n
210210
>2n : 2n
211211
>3n : 3n
@@ -215,7 +215,7 @@ bigUintArray = new BigUint64Array([1, 2, 3]);
215215
>bigUintArray : BigUint64Array
216216
>new BigUint64Array([1, 2, 3]) : any
217217
>BigUint64Array : any
218-
>[1, 2, 3] : number[]
218+
>[1, 2, 3] : [number, number, number]
219219
>1 : 1
220220
>2 : 2
221221
>3 : 3

tests/baselines/reference/castExpressionParentheses.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ declare var a;
1414
(<any>[1,3,]);
1515
>(<any>[1,3,]) : any
1616
><any>[1,3,] : any
17-
>[1,3,] : number[]
17+
>[1,3,] : [number, number]
1818
>1 : 1
1919
>3 : 3
2020

tests/baselines/reference/conditionalTypes1.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ function zeroOf<T extends number | string | boolean>(value: T) {
410410

411411
return <ZeroOf<T>>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false);
412412
><ZeroOf<T>>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false) : ZeroOf<T>
413-
>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false) : false | "" | 0
414-
>typeof value === "number" ? 0 : typeof value === "string" ? "" : false : false | "" | 0
413+
>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false) : false | 0 | ""
414+
>typeof value === "number" ? 0 : typeof value === "string" ? "" : false : false | 0 | ""
415415
>typeof value === "number" : boolean
416416
>typeof value : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
417417
>value : T
@@ -476,11 +476,11 @@ function f21<T extends number | string>(x: T, y: ZeroOf<T>) {
476476

477477
let z1: number | string = y;
478478
>z1 : string | number
479-
>y : "" | 0
479+
>y : 0 | ""
480480

481481
let z2: 0 | "" = y;
482-
>z2 : "" | 0
483-
>y : "" | 0
482+
>z2 : 0 | ""
483+
>y : 0 | ""
484484

485485
x = y; // Error
486486
>x = y : ZeroOf<T>

tests/baselines/reference/constructorOverloads2.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var f4 = new Foo([f1,f2,f3]);
6363
>f4 : Foo
6464
>new Foo([f1,f2,f3]) : Foo
6565
>Foo : typeof Foo
66-
>[f1,f2,f3] : Foo[]
66+
>[f1,f2,f3] : [Foo, Foo, Foo]
6767
>f1 : Foo
6868
>f2 : Foo
6969
>f3 : Foo

tests/baselines/reference/constructorOverloads3.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var f4 = new Foo([f1,f2,f3]);
5656
>f4 : Foo
5757
>new Foo([f1,f2,f3]) : Foo
5858
>Foo : typeof Foo
59-
>[f1,f2,f3] : Foo[]
59+
>[f1,f2,f3] : [Foo, Foo, Foo]
6060
>f1 : Foo
6161
>f2 : Foo
6262
>f3 : Foo

0 commit comments

Comments
 (0)