Fix tuple and array comparisons during identity checking (#32089)

This commit is contained in:
Wesley Wigham
2019-06-25 20:56:41 -07:00
committed by GitHub
parent 261952247a
commit 34eb5ddf75
2 changed files with 23 additions and 1 deletions

View File

@@ -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}`

View File

@@ -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");