Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Codebase Compiler Types

Nathan Shively-Sanders edited this pageSep 2, 2022 ·1 revision

Type Hierarchy

Root class:Type

How are properties stored and found on a type?

checkPropertyAccessExpressionOrQualifiedName

getDeclaredTypeOfSymbol vs getTypeOfSymbol

The problem is that symbols can have both types and values associated with them:

typeA=numberconstA="do not do this"

And the compiler needs a way to get the type of both the type and the const.So it usesgetDeclaredTypeOfSymbol for types andgetTypeOfSymbol[AtLocation] for values:

getDeclaredTypeOfSymbol(A)==numbergetTypeOfSymbol(A)==string

Confusingly, classes (and enums and aliases) declare both a type and a value, so, a tiny bit arbitrarily, the instance side is the type and the static side is the value:

classC{m(){}statics(){}}getTypeOfSymbol()=={new():C,s():void}==typeofCgetDeclaredTypeOfSymbol()=={m():void}==C

This kind of makes sense when you think about that C actually does when executed: it defines a value that is constructable.This leads to the "deconstructed class" pattern used in tricky situations, for example:

interfaceC{m():void}varC:{new():Cs:void}

Again, it's a tiny bit arbitrary to choose the static side as the value, since ultimately you get a value from calling new C() too.But the deconstructed class pattern shows that you can get away with writing just a type for the instance side, whereas you must write a value for the static side.

[1]: <src/compiler/checker.ts - function checkPropertyAccessExpressionOrQualifiedName(

Want to contribute to this Wiki?

Fork it and send a pull request.

News

Debugging TypeScript

Contributing to TypeScript

Building Tools for TypeScript

FAQs

The Main Repo

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp