Skip to content

Commit 14047ae

Browse files
committed
feat(type-compiler): resolve type name for classes
1 parent 3356af1 commit 14047ae

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/type-compiler/src/compiler.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,8 @@ export class ReflectionTransformer implements CustomTransformer {
13011301
this.extractPackStructOfType(member, program);
13021302
}
13031303

1304-
program.pushOp(ReflectionOp.class);
1304+
this.resolveClass(narrowed, program);
1305+
13051306
if (description) program.pushOp(ReflectionOp.description, program.findOrAddStackEntry(description));
13061307

13071308
if (narrowed.heritageClauses && narrowed.heritageClauses[0] && narrowed.heritageClauses[0].types[0]) {
@@ -2315,6 +2316,11 @@ export class ReflectionTransformer implements CustomTransformer {
23152316
program.pushOp(ReflectionOp.typeName, program.findOrAddStackEntry(typeName));
23162317
}
23172318

2319+
protected resolveClass(node: ClassDeclaration | ClassExpression, program: CompilerProgram) {
2320+
program.pushOp(ReflectionOp.class);
2321+
this.resolveTypeName(getIdentifierName(node.name!), program);
2322+
}
2323+
23182324
protected resolveTypeParameter(declaration: TypeParameterDeclaration, type: TypeReferenceNode | ExpressionWithTypeArguments, program: CompilerProgram) {
23192325
//check if `type` was used in an expression. if so, we need to resolve it from runtime, otherwise we mark it as T
23202326
const isUsedInFunction = isFunctionLike(declaration.parent);

packages/type/tests/compiler.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,22 @@ test('import types named import typeOnly has typeName', () => {
17871787
`);
17881788
});
17891789

1790+
test('class has typeName', () => {
1791+
const js = transpile(`
1792+
class Test {}
1793+
typeOf<Test>();
1794+
`);
1795+
const typeOf = typeOf2;
1796+
expect(eval(js)).toMatchInlineSnapshot(`
1797+
{
1798+
"classType": [Function],
1799+
"kind": 20,
1800+
"typeName": "Test",
1801+
"types": [],
1802+
}
1803+
`);
1804+
});
1805+
17901806
test('import types named import with disabled reflection', () => {
17911807
const js = transpile({
17921808
'app': `

0 commit comments

Comments
 (0)