pleerock
pleerock

Reputation: 18846

Difference between Symbol and Node in TypeScript Compiler API

Can somebody provide a clear definition of what are Symbol and Node in TypeScript compiler API, when and how they are used by compiler and common usage examples by API users.

Also good to know when object contains .symbol and when .aliasSymbol why and what's difference. (The reason I ask is because sometimes I find what I need in .aliasSymbol and sometimes just in .symbol. I would like to understand when compiler decides to use which in a short examples if possible.)

Upvotes: 13

Views: 1599

Answers (1)

Royston Shufflebotham
Royston Shufflebotham

Reputation: 970

Nodes are part of the Abstract Syntax Tree; these are purely syntactic constructs based on the text in compiled files without any attempt to layer type information on top.

Symbols are where the TS compiler has started to lay some more semantic constructs on top and you're starting to get type information.

If you have a TypeChecker in your hand you can jump from the AST world to the types/symbols world via checker.getTypeAtLocation(node).

There's some more helpful information on the 'TypeScript Deep Dive' web site about this: https://basarat.gitbook.io/typescript/overview

Upvotes: 10

Related Questions