Merge pull request #30917 from Microsoft/fixIntersectionUnionConstraint

Fix checking of intersection with union constraint
This commit is contained in:
Anders Hejlsberg 2019-04-14 20:37:41 -10:00 committed by GitHub
commit 3902ef78ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 5 deletions

View File

@ -7598,11 +7598,6 @@ namespace ts {
constraint = getConstraintOfType(constraint);
}
if (constraint) {
// A constraint that isn't a union type implies that the final type would be a non-union
// type as well. Since non-union constraints are of no interest, we can exit here.
if (!(constraint.flags & TypeFlags.Union)) {
return undefined;
}
constraints = append(constraints, constraint);
}
}

View File

@ -80,4 +80,9 @@ tests/cases/conformance/types/intersection/intersectionWithUnionConstraint.ts(12
type UnexpectedError<T extends PropertyKey> = T
type NoErrorHere<T extends PropertyKey> = T
// Repro from #30331
type a<T> = T extends Array<infer U> ? U : never;
type b<T> = { [K in a<T> & keyof T ]: 42 };

View File

@ -33,6 +33,11 @@ type Example<T, U> = { [K in keyof T]: K extends keyof U ? UnexpectedError<K> :
type UnexpectedError<T extends PropertyKey> = T
type NoErrorHere<T extends PropertyKey> = T
// Repro from #30331
type a<T> = T extends Array<infer U> ? U : never;
type b<T> = { [K in a<T> & keyof T ]: 42 };
//// [intersectionWithUnionConstraint.js]

View File

@ -112,3 +112,21 @@ type NoErrorHere<T extends PropertyKey> = T
>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --))
>T : Symbol(T, Decl(intersectionWithUnionConstraint.ts, 33, 17))
// Repro from #30331
type a<T> = T extends Array<infer U> ? U : never;
>a : Symbol(a, Decl(intersectionWithUnionConstraint.ts, 33, 43))
>T : Symbol(T, Decl(intersectionWithUnionConstraint.ts, 37, 7))
>T : Symbol(T, Decl(intersectionWithUnionConstraint.ts, 37, 7))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>U : Symbol(U, Decl(intersectionWithUnionConstraint.ts, 37, 33))
>U : Symbol(U, Decl(intersectionWithUnionConstraint.ts, 37, 33))
type b<T> = { [K in a<T> & keyof T ]: 42 };
>b : Symbol(b, Decl(intersectionWithUnionConstraint.ts, 37, 49))
>T : Symbol(T, Decl(intersectionWithUnionConstraint.ts, 38, 7))
>K : Symbol(K, Decl(intersectionWithUnionConstraint.ts, 38, 15))
>a : Symbol(a, Decl(intersectionWithUnionConstraint.ts, 33, 43))
>T : Symbol(T, Decl(intersectionWithUnionConstraint.ts, 38, 7))
>T : Symbol(T, Decl(intersectionWithUnionConstraint.ts, 38, 7))

View File

@ -84,3 +84,11 @@ type UnexpectedError<T extends PropertyKey> = T
type NoErrorHere<T extends PropertyKey> = T
>NoErrorHere : T
// Repro from #30331
type a<T> = T extends Array<infer U> ? U : never;
>a : a<T>
type b<T> = { [K in a<T> & keyof T ]: 42 };
>b : b<T>

View File

@ -34,3 +34,8 @@ type Example<T, U> = { [K in keyof T]: K extends keyof U ? UnexpectedError<K> :
type UnexpectedError<T extends PropertyKey> = T
type NoErrorHere<T extends PropertyKey> = T
// Repro from #30331
type a<T> = T extends Array<infer U> ? U : never;
type b<T> = { [K in a<T> & keyof T ]: 42 };