Skip to content

Commit a5ea55a

Browse files
committed
Ignore null, undefined, void when checking for discriminant property
1 parent 3f1ec7a commit a5ea55a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7837,14 +7837,17 @@ namespace ts {
78377837
}
78387838

78397839
function isDiscriminantProperty(type: Type, name: string) {
7840-
if (type && type.flags & TypeFlags.Union) {
7841-
const prop = getPropertyOfType(type, name);
7842-
if (prop && prop.flags & SymbolFlags.SyntheticProperty) {
7843-
if ((<TransientSymbol>prop).isDiscriminantProperty === undefined) {
7844-
(<TransientSymbol>prop).isDiscriminantProperty = !(<TransientSymbol>prop).hasCommonType &&
7845-
isUnitUnionType(getTypeOfSymbol(prop));
7846-
}
7847-
return (<TransientSymbol>prop).isDiscriminantProperty;
7840+
if (type) {
7841+
const nonNullType = getNonNullableType(type);
7842+
if (nonNullType.flags & TypeFlags.Union) {
7843+
const prop = getPropertyOfType(nonNullType, name);
7844+
if (prop && prop.flags & SymbolFlags.SyntheticProperty) {
7845+
if ((<TransientSymbol>prop).isDiscriminantProperty === undefined) {
7846+
(<TransientSymbol>prop).isDiscriminantProperty = !(<TransientSymbol>prop).hasCommonType &&
7847+
isUnitUnionType(getTypeOfSymbol(prop));
7848+
}
7849+
return (<TransientSymbol>prop).isDiscriminantProperty;
7850+
}
78487851
}
78497852
}
78507853
return false;

0 commit comments

Comments
 (0)