Exclude arrays and tuples from full intersection property check (#38395)

* Exclude arrays and tuples from full intersection property check

* Add regression test
This commit is contained in:
Anders Hejlsberg
2020-05-07 15:03:51 -07:00
committed by GitHub
parent 7798f532df
commit 0091fd6c64
6 changed files with 39 additions and 1 deletions
+1 -1
View File
@@ -15876,7 +15876,7 @@ namespace ts {
// recursive intersections that are structurally similar but not exactly identical. See #37854.
if (result && !inPropertyCheck && (
target.flags & TypeFlags.Intersection && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
isNonGenericObjectType(target) && source.flags & TypeFlags.Intersection && getApparentType(source).flags & TypeFlags.StructuredType && !some((<IntersectionType>source).types, t => !!(getObjectFlags(t) & ObjectFlags.NonInferrableType)))) {
isNonGenericObjectType(target) && !isArrayType(target) && !isTupleType(target) && source.flags & TypeFlags.Intersection && getApparentType(source).flags & TypeFlags.StructuredType && !some((<IntersectionType>source).types, t => !!(getObjectFlags(t) & ObjectFlags.NonInferrableType)))) {
inPropertyCheck = true;
result &= recursiveTypeRelatedTo(source, target, reportErrors, IntersectionState.PropertyCheck);
inPropertyCheck = false;
@@ -46,4 +46,9 @@ tests/cases/compiler/intersectionsAndOptionalProperties.ts(20,5): error TS2322:
~~~~~~~
!!! error TS2322: Type 'null' is not assignable to type 'number | undefined'.
}
// Repro from #38348
const yy: number[] & [number, ...number[]] = [1];
const xx: [number, ...number[]] = yy;
@@ -20,6 +20,11 @@ function foo(v: From) {
x = v; // Error
x.field = v.field; // Error
}
// Repro from #38348
const yy: number[] & [number, ...number[]] = [1];
const xx: [number, ...number[]] = yy;
//// [intersectionsAndOptionalProperties.js]
@@ -31,3 +36,6 @@ function foo(v) {
x = v; // Error
x.field = v.field; // Error
}
// Repro from #38348
var yy = [1];
var xx = yy;
@@ -62,3 +62,12 @@ function foo(v: From) {
>field : Symbol(field, Decl(intersectionsAndOptionalProperties.ts, 14, 14))
}
// Repro from #38348
const yy: number[] & [number, ...number[]] = [1];
>yy : Symbol(yy, Decl(intersectionsAndOptionalProperties.ts, 24, 5))
const xx: [number, ...number[]] = yy;
>xx : Symbol(xx, Decl(intersectionsAndOptionalProperties.ts, 25, 5))
>yy : Symbol(yy, Decl(intersectionsAndOptionalProperties.ts, 24, 5))
@@ -63,3 +63,14 @@ function foo(v: From) {
>field : null
}
// Repro from #38348
const yy: number[] & [number, ...number[]] = [1];
>yy : number[] & [number, ...number[]]
>[1] : [number]
>1 : 1
const xx: [number, ...number[]] = yy;
>xx : [number, ...number[]]
>yy : number[] & [number, ...number[]]
@@ -21,3 +21,8 @@ function foo(v: From) {
x = v; // Error
x.field = v.field; // Error
}
// Repro from #38348
const yy: number[] & [number, ...number[]] = [1];
const xx: [number, ...number[]] = yy;