@@ -3266,6 +3266,9 @@ namespace ts {
3266
3266
writeTypeList(type.typeArguments.slice(0, getTypeReferenceArity(type)), SyntaxKind.CommaToken);
3267
3267
writePunctuation(writer, SyntaxKind.CloseBracketToken);
3268
3268
}
3269
+ else if (type.symbol.valueDeclaration && type.symbol.valueDeclaration.kind === SyntaxKind.ClassExpression) {
3270
+ writeAnonymousType(getDeclaredTypeOfClassOrInterface(type.symbol), flags);
3271
+ }
3269
3272
else {
3270
3273
// Write the type reference in the format f<A>.g<B>.C<X, Y> where A and B are type arguments
3271
3274
// for outer type parameters, and f and g are the respective declaring containers of those
@@ -3313,7 +3316,7 @@ namespace ts {
3313
3316
const symbol = type.symbol;
3314
3317
if (symbol) {
3315
3318
// Always use 'typeof T' for type of class, enum, and module objects
3316
- if (symbol.flags & SymbolFlags.Class && !getBaseTypeVariableOfClass(symbol) ||
3319
+ if (symbol.flags & SymbolFlags.Class && !getBaseTypeVariableOfClass(symbol) && symbol.valueDeclaration.kind !== SyntaxKind.ClassExpression ||
3317
3320
symbol.flags & (SymbolFlags.Enum | SymbolFlags.ValueModule)) {
3318
3321
writeTypeOfSymbol(type, flags);
3319
3322
}
@@ -3335,12 +3338,23 @@ namespace ts {
3335
3338
else {
3336
3339
// Since instantiations of the same anonymous type have the same symbol, tracking symbols instead
3337
3340
// of types allows us to catch circular references to instantiations of the same anonymous type
3341
+ // However, in case of class expressions, we want to write both the static side and the instance side.
3342
+ // We skip adding the static side so that the instance side has a chance to be written
3343
+ // before checking for circular references.
3338
3344
if (!symbolStack) {
3339
3345
symbolStack = [];
3340
3346
}
3341
- symbolStack.push(symbol);
3342
- writeLiteralType(type, flags);
3343
- symbolStack.pop();
3347
+ const isConstructorObject = type.flags & TypeFlags.Object &&
3348
+ getObjectFlags(type) & ObjectFlags.Anonymous &&
3349
+ type.symbol && type.symbol.flags & SymbolFlags.Class;
3350
+ if (isConstructorObject) {
3351
+ writeLiteralType(type, flags);
3352
+ }
3353
+ else {
3354
+ symbolStack.push(symbol);
3355
+ writeLiteralType(type, flags);
3356
+ symbolStack.pop();
3357
+ }
3344
3358
}
3345
3359
}
3346
3360
else {
0 commit comments