Skip to content

Commit d069875

Browse files
committed
Allow discriminant property to contain some non-unit types
1 parent 07966dc commit d069875

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12919,6 +12919,10 @@ namespace ts {
1291912919
isUnitType(type);
1292012920
}
1292112921

12922+
function maybeUnitType(type: Type): boolean {
12923+
return type.flags & TypeFlags.Union ? some((<UnionType>type).types, isUnitType) : isUnitType(type);
12924+
}
12925+
1292212926
function getBaseTypeOfLiteralType(type: Type): Type {
1292312927
return type.flags & TypeFlags.EnumLiteral ? getBaseTypeOfEnumLiteralType(<LiteralType>type) :
1292412928
type.flags & TypeFlags.StringLiteral ? stringType :
@@ -14217,7 +14221,7 @@ namespace ts {
1421714221
const prop = getUnionOrIntersectionProperty(<UnionType>type, name);
1421814222
if (prop && getCheckFlags(prop) & CheckFlags.SyntheticProperty) {
1421914223
if ((<TransientSymbol>prop).isDiscriminantProperty === undefined) {
14220-
(<TransientSymbol>prop).isDiscriminantProperty = !!((<TransientSymbol>prop).checkFlags & CheckFlags.HasNonUniformType) && isLiteralType(getTypeOfSymbol(prop));
14224+
(<TransientSymbol>prop).isDiscriminantProperty = !!((<TransientSymbol>prop).checkFlags & CheckFlags.HasNonUniformType) && maybeUnitType(getTypeOfSymbol(prop));
1422114225
}
1422214226
return !!(<TransientSymbol>prop).isDiscriminantProperty;
1422314227
}

0 commit comments

Comments
 (0)