Skip to content

Commit 0344cae

Browse files
committed
fix getConstructorTypeOfClassLikeDeclaration
1 parent ef522f2 commit 0344cae

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 3.19.0
2+
3+
**Features:**
4+
5+
* `getSymbolOfClassLikeDeclaration` to retrieve the symbol of class declarations and expressions regardless whether they have a name or not
6+
7+
**Bugfixes:**
8+
9+
* `getConstructorTypeOfClassLikeDeclaration` now really returns the constructor type (the static side of the class), previously it returned the instance type
10+
111
# 3.18.0
212

313
**Features:**

util/type.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,20 @@ export function getPropertyNameFromType(type: ts.Type): PropertyName | undefined
285285
};
286286
}
287287

288+
export function getSymbolOfClassLikeDeclaration(node: ts.ClassLikeDeclaration, checker: ts.TypeChecker) {
289+
return node.name !== undefined ? checker.getSymbolAtLocation(node.name)! : checker.getTypeAtLocation(node).symbol!;
290+
}
291+
288292
export function getConstructorTypeOfClassLikeDeclaration(node: ts.ClassLikeDeclaration, checker: ts.TypeChecker) {
289-
return checker.getDeclaredTypeOfSymbol(
290-
node.name !== undefined ? checker.getSymbolAtLocation(node.name)! : checker.getTypeAtLocation(node).symbol!,
291-
);
293+
return node.kind === ts.SyntaxKind.ClassExpression
294+
? checker.getTypeAtLocation(node)
295+
: checker.getTypeOfSymbolAtLocation(getSymbolOfClassLikeDeclaration(node, checker), node);
292296
}
293297

294298
export function getInstanceTypeOfClassLikeDeclaration(node: ts.ClassLikeDeclaration, checker: ts.TypeChecker) {
295299
return node.kind === ts.SyntaxKind.ClassDeclaration
296300
? checker.getTypeAtLocation(node)
297-
: checker.getTypeOfSymbolAtLocation(checker.getTypeAtLocation(node).getProperty('prototype')!, node);
301+
: checker.getDeclaredTypeOfSymbol(getSymbolOfClassLikeDeclaration(node, checker));
298302
}
299303

300304
export function getIteratorYieldResultFromIteratorResult(type: ts.Type, node: ts.Node, checker: ts.TypeChecker): ts.Type {

0 commit comments

Comments
 (0)