Skip to content

Commit 34eb5dd

Browse files
authored
Fix tuple and array comparisons during identity checking (microsoft#32089)
1 parent 2619522 commit 34eb5dd

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13321,7 +13321,14 @@ namespace ts {
1332113321
}
1332213322
}
1332313323
else if (isReadonlyArrayType(target) ? isArrayType(source) || isTupleType(source) : isArrayType(target) && isTupleType(source) && !source.target.readonly) {
13324-
return isRelatedTo(getIndexTypeOfType(source, IndexKind.Number) || anyType, getIndexTypeOfType(target, IndexKind.Number) || anyType, reportErrors);
13324+
if (relation !== identityRelation) {
13325+
return isRelatedTo(getIndexTypeOfType(source, IndexKind.Number) || anyType, getIndexTypeOfType(target, IndexKind.Number) || anyType, reportErrors);
13326+
}
13327+
else {
13328+
// By flags alone, we know that the `target` is a readonly array while the source is a normal array or tuple
13329+
// or `target` is an array and source is a tuple - in both cases the types cannot be identical, by construction
13330+
return Ternary.False;
13331+
}
1332513332
}
1332613333
// Consider a fresh empty object literal type "closed" under the subtype relationship - this way `{} <- {[idx: string]: any} <- fresh({})`
1332713334
// and not `{} <- fresh({}) <- {[idx: string]: any}`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="fourslash.ts" />
2+
////type TypeEq<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;
3+
////
4+
////const /*2*/test1: TypeEq<number[], [number, ...number[]]> = false;
5+
////
6+
////declare const foo: [number, ...number[]];
7+
////declare const bar: number[];
8+
////
9+
////const /*1*/test2: TypeEq<typeof foo, typeof bar> = false;
10+
11+
goTo.marker("1");
12+
verify.quickInfoIs("const test2: false");
13+
14+
goTo.marker("2");
15+
verify.quickInfoIs("const test1: false");

0 commit comments

Comments
 (0)