Skip to content

Commit e501cc9

Browse files
committed
Repeatedly unwrap/simplify until no more can be performed
1 parent 3b28100 commit e501cc9

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12776,26 +12776,17 @@ namespace ts {
1277612776
if (isFreshLiteralType(target)) {
1277712777
target = (<FreshableType>target).regularType;
1277812778
}
12779-
if (source.flags & TypeFlags.Substitution) {
12780-
source = (<SubstitutionType>source).substitute;
12781-
}
12782-
if (target.flags & TypeFlags.Substitution) {
12783-
target = (<SubstitutionType>target).typeVariable;
12784-
}
12785-
if (source.flags & TypeFlags.Simplifiable) {
12786-
source = getSimplifiedType(source, /*writing*/ false);
12787-
}
12788-
if (target.flags & TypeFlags.Simplifiable) {
12789-
target = getSimplifiedType(target, /*writing*/ true);
12790-
}
12791-
if (source.flags & TypeFlags.Substitution) {
12792-
source = (<SubstitutionType>source).substitute;
12793-
}
12794-
if (target.flags & TypeFlags.Substitution) {
12795-
target = (<SubstitutionType>target).typeVariable;
12779+
while (true) {
12780+
const s = source.flags & TypeFlags.Substitution ? source = (<SubstitutionType>source).substitute :
12781+
source.flags & TypeFlags.Simplifiable ? getSimplifiedType(source, /*writing*/ false) :
12782+
source;
12783+
const t = target.flags & TypeFlags.Substitution ? (<SubstitutionType>target).typeVariable :
12784+
target.flags & TypeFlags.Simplifiable ? getSimplifiedType(target, /*writing*/ true) :
12785+
target;
12786+
if (s === source && t === target) break;
12787+
source = s;
12788+
target = t;
1279612789
}
12797-
Debug.assert(!(source.flags & TypeFlags.Substitution), "Source type was a substitution - substitutes are unhandled in relationship checking");
12798-
Debug.assert(!(target.flags & TypeFlags.Substitution), "Target type was a substitution - substitutes are unhandled in relationship checking");
1279912790

1280012791
// Try to see if we're relating something like `Foo` -> `Bar | null | undefined`.
1280112792
// If so, reporting the `null` and `undefined` in the type is hardly useful.

0 commit comments

Comments
 (0)