Skip to content

Commit c73affd

Browse files
committed
Normalize type references before relating them in isRelatedTo
1 parent ca4486a commit c73affd

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14240,6 +14240,14 @@ namespace ts {
1424014240
return getObjectFlags(source) & ObjectFlags.JsxAttributes && !isUnhyphenatedJsxName(sourceProp.escapedName);
1424114241
}
1424214242

14243+
function getNormalizedType(type: Type, writing: boolean): Type {
14244+
return isFreshLiteralType(type) ? (<FreshableType>type).regularType :
14245+
getObjectFlags(type) & ObjectFlags.Reference && (<TypeReference>type).node ? createTypeReference((<TypeReference>type).target, getTypeArguments(<TypeReference>type)) :
14246+
type.flags & TypeFlags.Substitution ? writing ? (<SubstitutionType>type).typeVariable : (<SubstitutionType>type).substitute :
14247+
type.flags & TypeFlags.Simplifiable ? getSimplifiedType(type, writing) :
14248+
type;
14249+
}
14250+
1424314251
/**
1424414252
* Checks if 'source' is related to 'target' (e.g.: is a assignable to).
1424514253
* @param source The left-hand-side of the relation.
@@ -14546,24 +14554,8 @@ namespace ts {
1454614554
* * Ternary.False if they are not related.
1454714555
*/
1454814556
function isRelatedTo(source: Type, target: Type, reportErrors = false, headMessage?: DiagnosticMessage, isApparentIntersectionConstituent?: boolean): Ternary {
14549-
if (isFreshLiteralType(source)) {
14550-
source = (<FreshableType>source).regularType;
14551-
}
14552-
if (isFreshLiteralType(target)) {
14553-
target = (<FreshableType>target).regularType;
14554-
}
14555-
if (source.flags & TypeFlags.Substitution) {
14556-
source = (<SubstitutionType>source).substitute;
14557-
}
14558-
if (target.flags & TypeFlags.Substitution) {
14559-
target = (<SubstitutionType>target).typeVariable;
14560-
}
14561-
if (source.flags & TypeFlags.Simplifiable) {
14562-
source = getSimplifiedType(source, /*writing*/ false);
14563-
}
14564-
if (target.flags & TypeFlags.Simplifiable) {
14565-
target = getSimplifiedType(target, /*writing*/ true);
14566-
}
14557+
source = getNormalizedType(source, /*writing*/ false);
14558+
target = getNormalizedType(target, /*writing*/ true);
1456714559

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

0 commit comments

Comments
 (0)