Skip to content

API: how to get Symbol of anonymous class? #26511

Closed
@ajafff

Description

@ajafff

TypeScript Version: 3.1.0-dev.20180813

Search Terms:

Code

declare let node: ts.ClassExpression; // (class {})
checker.getSymbolAtLocation(node); // undefined;

Expected behavior:
getSymbolAtLocation returns the symbol of the class.

Actual behavior:
For named ClassLikeDeclarations I can use getSymbolAtLocation(node.name) but that will obviously not work if there is no name.

My current workaround is ts.getTypeAtLocation(node).symbol!.

Why doesn't getSymbolAtLocation simply return node.symbol if none of the conditions match?

In addition there is some special handling of FunctionKeyword to get the symbol of anonymous functions. Could something similar be implemented for ClassKeyword?

Metadata

Metadata

Assignees

Labels

QuestionAn issue which isn't directly actionable in code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions