File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -12919,10 +12919,6 @@ namespace ts {
12919
12919
isUnitType(type);
12920
12920
}
12921
12921
12922
- function maybeUnitType(type: Type): boolean {
12923
- return type.flags & TypeFlags.Union ? some((<UnionType>type).types, isUnitType) : isUnitType(type);
12924
- }
12925
-
12926
12922
function getBaseTypeOfLiteralType(type: Type): Type {
12927
12923
return type.flags & TypeFlags.EnumLiteral ? getBaseTypeOfEnumLiteralType(<LiteralType>type) :
12928
12924
type.flags & TypeFlags.StringLiteral ? stringType :
@@ -14216,12 +14212,26 @@ namespace ts {
14216
14212
return undefined;
14217
14213
}
14218
14214
14215
+ function isDiscriminantType(type: Type): boolean {
14216
+ if (type.flags & TypeFlags.Union) {
14217
+ if (type.flags & (TypeFlags.Boolean | TypeFlags.EnumLiteral)) {
14218
+ return true;
14219
+ }
14220
+ let combined = 0;
14221
+ for (const t of (<UnionType>type).types) combined |= t.flags;
14222
+ if (combined & TypeFlags.Unit && !(combined & TypeFlags.Instantiable)) {
14223
+ return true;
14224
+ }
14225
+ }
14226
+ return false;
14227
+ }
14228
+
14219
14229
function isDiscriminantProperty(type: Type | undefined, name: __String) {
14220
14230
if (type && type.flags & TypeFlags.Union) {
14221
14231
const prop = getUnionOrIntersectionProperty(<UnionType>type, name);
14222
14232
if (prop && getCheckFlags(prop) & CheckFlags.SyntheticProperty) {
14223
14233
if ((<TransientSymbol>prop).isDiscriminantProperty === undefined) {
14224
- (<TransientSymbol>prop).isDiscriminantProperty = !!((<TransientSymbol>prop).checkFlags & CheckFlags.HasNonUniformType) && maybeUnitType (getTypeOfSymbol(prop));
14234
+ (<TransientSymbol>prop).isDiscriminantProperty = !!((<TransientSymbol>prop).checkFlags & CheckFlags.HasNonUniformType) && isDiscriminantType (getTypeOfSymbol(prop));
14225
14235
}
14226
14236
return !!(<TransientSymbol>prop).isDiscriminantProperty;
14227
14237
}
You can’t perform that action at this time.
0 commit comments