mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
Fix tuple and array comparisons during identity checking (#32089)
This commit is contained in:
@@ -13321,7 +13321,14 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else if (isReadonlyArrayType(target) ? isArrayType(source) || isTupleType(source) : isArrayType(target) && isTupleType(source) && !source.target.readonly) {
|
||||
return isRelatedTo(getIndexTypeOfType(source, IndexKind.Number) || anyType, getIndexTypeOfType(target, IndexKind.Number) || anyType, reportErrors);
|
||||
if (relation !== identityRelation) {
|
||||
return isRelatedTo(getIndexTypeOfType(source, IndexKind.Number) || anyType, getIndexTypeOfType(target, IndexKind.Number) || anyType, reportErrors);
|
||||
}
|
||||
else {
|
||||
// By flags alone, we know that the `target` is a readonly array while the source is a normal array or tuple
|
||||
// or `target` is an array and source is a tuple - in both cases the types cannot be identical, by construction
|
||||
return Ternary.False;
|
||||
}
|
||||
}
|
||||
// Consider a fresh empty object literal type "closed" under the subtype relationship - this way `{} <- {[idx: string]: any} <- fresh({})`
|
||||
// and not `{} <- fresh({}) <- {[idx: string]: any}`
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
////type TypeEq<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;
|
||||
////
|
||||
////const /*2*/test1: TypeEq<number[], [number, ...number[]]> = false;
|
||||
////
|
||||
////declare const foo: [number, ...number[]];
|
||||
////declare const bar: number[];
|
||||
////
|
||||
////const /*1*/test2: TypeEq<typeof foo, typeof bar> = false;
|
||||
|
||||
goTo.marker("1");
|
||||
verify.quickInfoIs("const test2: false");
|
||||
|
||||
goTo.marker("2");
|
||||
verify.quickInfoIs("const test1: false");
|
||||
Reference in New Issue
Block a user