Skip to content

Commit 44ce59d

Browse files
authored
cache type for empty type literal (#11934)
cache type for empty type literal
1 parent 980f9fd commit 44ce59d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/compiler/checker.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ namespace ts {
138138
const silentNeverType = createIntrinsicType(TypeFlags.Never, "never");
139139

140140
const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
141+
142+
const emptyTypeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral | SymbolFlags.Transient, "__type");
143+
emptyTypeLiteralSymbol.members = createMap<Symbol>();
144+
const emptyTypeLiteralType = createAnonymousType(emptyTypeLiteralSymbol, emptySymbols, emptyArray, emptyArray, undefined, undefined);
145+
141146
const emptyGenericType = <GenericType><ObjectType>createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
142147
emptyGenericType.instantiations = createMap<TypeReference>();
143148

@@ -5696,10 +5701,15 @@ namespace ts {
56965701
const links = getNodeLinks(node);
56975702
if (!links.resolvedType) {
56985703
// Deferred resolution of members is handled by resolveObjectTypeMembers
5699-
const type = createObjectType(ObjectFlags.Anonymous, node.symbol);
5700-
type.aliasSymbol = aliasSymbol;
5701-
type.aliasTypeArguments = aliasTypeArguments;
5702-
links.resolvedType = type;
5704+
if (isEmpty(node.symbol.members) && !aliasSymbol && !aliasTypeArguments) {
5705+
links.resolvedType = emptyTypeLiteralType;
5706+
}
5707+
else {
5708+
const type = createObjectType(ObjectFlags.Anonymous, node.symbol);
5709+
type.aliasSymbol = aliasSymbol;
5710+
type.aliasTypeArguments = aliasTypeArguments;
5711+
links.resolvedType = type;
5712+
}
57035713
}
57045714
return links.resolvedType;
57055715
}
@@ -6036,6 +6046,9 @@ namespace ts {
60366046
}
60376047

60386048
function isSymbolInScopeOfMappedTypeParameter(symbol: Symbol, mapper: TypeMapper) {
6049+
if (!(symbol.declarations && symbol.declarations.length)) {
6050+
return false;
6051+
}
60396052
const mappedTypes = mapper.mappedTypes;
60406053
// Starting with the parent of the symbol's declaration, check if the mapper maps any of
60416054
// the type parameters introduced by enclosing declarations. We just pick the first

0 commit comments

Comments
 (0)