Skip to content

Commit 04387e6

Browse files
committedJan 5, 2022
Migrate more of the wiki
1 parent 0331f78 commit 04387e6

File tree

2 files changed

+133
-46
lines changed

2 files changed

+133
-46
lines changed
 

‎GLOSSARY.md

+68-46
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
### Terminology from inside the codebase
22

3-
* **Core TypeScript Compiler**
3+
- **Core TypeScript Compiler**
44

5-
* **Parser:** Starting from a set of sources, and following the productions of the language grammar, to generate an Abstract Syntax Tree (AST). Also: [see Parser](https://basarat.gitbooks.io/typescript/docs/compiler/parser.html),
5+
- **Parser:** Starting from a set of sources, and following the productions of the language grammar, to generate an Abstract Syntax Tree (AST). Also: [see Parser](https://basarat.gitbooks.io/typescript/docs/compiler/parser.html),
66

7-
* **Binder:** Linking declarations contributing to the same structure using a Symbol (e.g. different declarations of the same interface or module, or a function and a module with the same name). This allows the type system to reason about these named declarations. [See Binder](https://basarat.gitbooks.io/typescript/docs/compiler/binder.html)
8-
* **Type resolver/ Checker:** Resolving types of each construct, checking semantic operations and generate diagnostics as appropriate. [See Checker](https://basarat.gitbooks.io/typescript/docs/compiler/checker.html)
7+
- **Binder:** Linking declarations contributing to the same structure using a Symbol (e.g. different declarations of the same interface or module, or a function and a module with the same name). This allows the type system to reason about these named declarations. [See Binder](https://basarat.gitbooks.io/typescript/docs/compiler/binder.html)
8+
- **Type resolver/ Checker:** Resolving types of each construct, checking semantic operations and generate diagnostics as appropriate. [See Checker](https://basarat.gitbooks.io/typescript/docs/compiler/checker.html)
99

10-
* **Emitter:** Output generated from a set of inputs (.ts and .d.ts) files can be one of: JavaScript (.js), definitions (.d.ts), or source maps (.js.map)
10+
- **Emitter:** Output generated from a set of inputs (.ts and .d.ts) files can be one of: JavaScript (.js), definitions (.d.ts), or source maps (.js.map)
1111

12-
* **Pre-processor:** The "Compilation Context" refers to all files involved in a "program". The context is created by inspecting all files passed in to the compiler on the command line, in order, and then adding any files they may reference directly or indirectly through `import` statements and `/// <reference path=... />` tags.
13-
The result of walking the reference graph is an ordered list of source files, that constitute the program.
14-
When resolving imports, preference is given to ".ts" files over ".d.ts" files to ensure the most up-to-date files are processed.
15-
The compiler does a node-like process to resolve imports by walking up the directory chain to find a source file with a .ts or .d.ts extension matching the requested import.
16-
Failed import resolution does not result in an error, as an ambient module could be already declared.
12+
- **Pre-processor:** The "Compilation Context" refers to all files involved in a "program". The context is created by inspecting all files passed in to the compiler on the command line, in order, and then adding any files they may reference directly or indirectly through `import` statements and `/// <reference path=... />` tags.
13+
The result of walking the reference graph is an ordered list of source files, that constitute the program.
14+
When resolving imports, preference is given to ".ts" files over ".d.ts" files to ensure the most up-to-date files are processed.
15+
The compiler does a node-like process to resolve imports by walking up the directory chain to find a source file with a .ts or .d.ts extension matching the requested import.
16+
Failed import resolution does not result in an error, as an ambient module could be already declared.
1717

18-
* **Standalone compiler (tsc):** The batch compilation CLI. Mainly handle reading and writing files for different supported engines (e.g. Node.js)
18+
- **Standalone compiler (tsc):** The batch compilation CLI. Mainly handle reading and writing files for different supported engines (e.g. Node.js)
1919

20-
* **Language Service:** The "Language Service" exposes an additional layer around the core compiler pipeline that are best suiting editor-like applications.
21-
The language service supports the common set of a typical editor operations like statement completions, signature help, code formatting and outlining, colorization, etc... Basic re-factoring like rename, Debugging interface helpers like validating breakpoints as well as TypeScript-specific features like support of incremental compilation (--watch equivalent on the command-line). The language service is designed to efficiently handle scenarios with files changing over time within a long-lived compilation context; in that sense, the language service provides a slightly different perspective about working with programs and source files from that of the other compiler interfaces.
22-
> Please refer to the [[Using the Language Service API]] page for more details.
20+
- **Language Service:** The "Language Service" exposes an additional layer around the core compiler pipeline that are best suiting editor-like applications.
21+
The language service supports the common set of a typical editor operations like statement completions, signature help, code formatting and outlining, colorization, etc... Basic re-factoring like rename, Debugging interface helpers like validating breakpoints as well as TypeScript-specific features like support of incremental compilation (--watch equivalent on the command-line). The language service is designed to efficiently handle scenarios with files changing over time within a long-lived compilation context; in that sense, the language service provides a slightly different perspective about working with programs and source files from that of the other compiler interfaces.
2322

24-
* **Standalone Server (tsserver):** The `tsserver` wraps the compiler and services layer, and exposes them through a JSON protocol.
25-
> Please refer to the [[Standalone Server (tsserver)]] for more details.
23+
> Please refer to the [[Using the Language Service API]] page for more details.
24+
25+
- **Standalone Server (tsserver):** The `tsserver` wraps the compiler and services layer, and exposes them through a JSON protocol.
26+
> Please refer to the [[Standalone Server (tsserver)]] for more details.
2627
2728
### Type stuff which can be see outside the compilers
2829

29-
* Node: The basic building block of the Abstract Syntax Tree (AST). In general node represent non-terminals in the language grammar; some terminals are kept in the tree such as identifiers and literals.
30+
- Node: The basic building block of the Abstract Syntax Tree (AST). In general node represent non-terminals in the language grammar; some terminals are kept in the tree such as identifiers and literals.
3031

31-
* SourceFile: The AST of a given source file. A SourceFile is itself a Node; it provides an additional set of interfaces to access the raw text of the file, references in the file, the list of identifiers in the file, and mapping from a position in the file to a line and character numbers.
32+
- SourceFile: The AST of a given source file. A SourceFile is itself a Node; it provides an additional set of interfaces to access the raw text of the file, references in the file, the list of identifiers in the file, and mapping from a position in the file to a line and character numbers.
3233

33-
* Program: A collection of SourceFiles and a set of compilation options that represent a compilation unit. The program is the main entry point to the type system and code generation.
34+
- Program: A collection of SourceFiles and a set of compilation options that represent a compilation unit. The program is the main entry point to the type system and code generation.
3435

35-
* Symbol: A named declaration. Symbols are created as a result of binding. Symbols connect declaration nodes in the tree to other declarations contributing to the same entity. Symbols are the basic building block of the semantic system.
36+
- Symbol: A named declaration. Symbols are created as a result of binding. Symbols connect declaration nodes in the tree to other declarations contributing to the same entity. Symbols are the basic building block of the semantic system.
3637

37-
* `Type`: Types are the other part of the semantic system. Types can be named (e.g. classes and interfaces), or anonymous (e.g. object types).
38+
- `Type`: Types are the other part of the semantic system. Types can be named (e.g. classes and interfaces), or anonymous (e.g. object types).
3839

39-
* Signature``: There are three types of signatures in the language: call, construct and index signatures.
40+
- Signature``: There are three types of signatures in the language: call, construct and index signatures.
4041

41-
- `Transient Symbol` - A symbol created in the checker, as opposed to in the binder
42-
- `Freshness` - When a literal type is first created and not expanded by hitting a mutable location, see [Widening
42+
* `Transient Symbol` - A symbol created in the checker, as opposed to in the binder
43+
* `Freshness` - When a literal type is first created and not expanded by hitting a mutable location, see [Widening
4344
and Narrowing in TypeScript][wnn].
4445

45-
- `Expando` - This is [the term](https://developer.mozilla.org/en-US/docs/Glossary/Expando) used to describe taking a JS object and adding new things to it which expands the type's shape
46+
* `Expando` - This is [the term](https://developer.mozilla.org/en-US/docs/Glossary/Expando) used to describe taking a JS object and adding new things to it which expands the type's shape
4647

4748
```js
4849
function doSomething() {}
49-
doSomething.doSomethingElse = () => {}
50+
doSomething.doSomethingElse = () => {};
5051
```
51-
52-
In TS, this is only allowed for adding properties to functions. In JS, this is a normal pattern in old school code for all kinds of objects. TypeScript will augment the types for `doSomething` to add `doSomethingElse` in the type system in both.
5352

53+
In TS, this is only allowed for adding properties to functions. In JS, this is a normal pattern in old school code for all kinds of objects. TypeScript will augment the types for `doSomething` to add `doSomethingElse` in the type system in both.
5454

55-
- `Structural Type System` - A school of types system where the way types are compared is via the structure of
55+
* `Structural Type System` - A school of types system where the way types are compared is via the structure of
5656
their properties.
5757

5858
For example:
@@ -72,7 +72,20 @@ The language service supports the common set of a typical editor operations like
7272
These two are the exact same inside TypeScript. The basic rule for TypeScript’s structural type system is that
7373
`x` is compatible with `y` if `y` has at least the same members as `x`.
7474

75-
* `Literal` - A literal type is a type that only has a single value, e.g. `true`, `1`, `"abc"`, `undefined`.
75+
* `Laziness` To support language services that respond interactively, the compiler is lazy: it does not calculate any information until it is required.
76+
This allows it to respond quickly when the language service requests the type of a variable or its members.
77+
Unfortunately, laziness also makes the compiler code more complicated.
78+
79+
As an overview, after parsing is complete, the binder does nothing but identify symbols.
80+
The checker then waits until a particular symbol is requested to calculate type information, etc.
81+
82+
* `Immutability` - Each phase of the compiler (parser, binder, etc -- see below for details) treats data structures from the previous phases as immutable.
83+
In addition, data structures created within each phase are not usually modified after their creation.
84+
This requires a look-aside table in some cases.
85+
For example, because the binder only looks at one file at a time, the checker needs a merged-symbols table to track merged declarations.
86+
It checks whether a symbol has an entry in the merged-symbols table each time before it uses a symbol.
87+
88+
- `Literal` - A literal type is a type that only has a single value, e.g. `true`, `1`, `"abc"`, `undefined`.
7689

7790
For immutable objects, TypeScript creates a literal type which is the value. For mutable objects TypeScript
7891
uses the general type that the literal matches. See [#10676](https://github.com/Microsoft/TypeScript/pull/10676)
@@ -96,21 +109,22 @@ The language service supports the common set of a typical editor operations like
96109

97110
Literal types are sometimes called unit types, because they have only one ("unit") value.
98111

99-
- `Control Flow Analysis` - using the natural branching and execution path of code to change the types at
112+
* `Control Flow Analysis` - using the natural branching and execution path of code to change the types at
100113
different locations in your source code by static analysis.
101114

102115
```ts
103-
type Bird = { color: string, flaps: true };
104-
type Tiger = { color: string, stripes: true };
105-
declare animal: Bird | Tiger
116+
type Bird = { color: string; flaps: true };
117+
type Tiger = { color: string; stripes: true };
118+
declare;
119+
animal: Bird | Tiger;
106120

107121
if ("stripes" in animal) {
108122
// Inside here animal is only a tiger, because TS could figure out that
109123
// the only way you could get here is when animal is a tiger and not a bird
110124
}
111125
```
112126

113-
- `Generics` - A way to have variables inside a type system.
127+
* `Generics` - A way to have variables inside a type system.
114128

115129
```ts
116130
function first(array: any[]): any {
@@ -147,7 +161,7 @@ The language service supports the common set of a typical editor operations like
147161
first<string>(["a", "b", "c"]);
148162
```
149163

150-
* `Outer type parameter` - A type parameter declared in a parent generic construct:
164+
- `Outer type parameter` - A type parameter declared in a parent generic construct:
151165

152166
```ts
153167
class Parent<T> {
@@ -158,7 +172,7 @@ The language service supports the common set of a typical editor operations like
158172
}
159173
```
160174

161-
* `Narrowing` - Taking a union of types and reducing it to fewer options.
175+
- `Narrowing` - Taking a union of types and reducing it to fewer options.
162176

163177
A great case is when using `--strictNullCheck` when using control flow analysis
164178

@@ -174,7 +188,7 @@ The language service supports the common set of a typical editor operations like
174188
}
175189
```
176190

177-
- `Expanding` - The opposite of narrowing, taking a type and converting it to have more potential values.
191+
* `Expanding` - The opposite of narrowing, taking a type and converting it to have more potential values.
178192

179193
```ts
180194
const helloWorld = "Hello World"; // Type; "Hello World"
@@ -193,17 +207,21 @@ expanded version of `"Hello World"` which went from one value ever, to any known
193207

194208
```ts
195209
// @filename: one.ts
196-
interface I { a }
210+
interface I {
211+
a;
212+
}
197213
// @filename: two.ts
198-
interface I { b }
214+
interface I {
215+
b;
216+
}
199217
```
200218

201219
The binder creates two symbols for I, one in each file. Then the checker creates a merged symbol that has both declarations.
202220

203221
2. Synthetic properties
204222

205223
```ts
206-
type Nats = Record<'one' | 'two', number>
224+
type Nats = Record<"one" | "two", number>;
207225
```
208226

209227
The binder doesn't create any symbols for `one` or `two`, because those properties don't exist until the Record mapped type creates them.
@@ -212,13 +230,13 @@ expanded version of `"Hello World"` which went from one value ever, to any known
212230

213231
```js
214232
var f = function g() {
215-
g.expando1 = {}
216-
217-
}
218-
f.expando2 = {}
233+
g.expando1 = {};
234+
};
235+
f.expando2 = {};
219236
```
220237

221238
People can put expando properties on a function expression inside or outside the function, using different names.
239+
222240
- `Partial Type` -
223241
- `Synthetic` - a property that doesn't have a declaration in source.
224242
- `Union Types`
@@ -273,7 +291,11 @@ TypeScript lets you use these as convenient containers with known types.
273291
// Any item has to say what it is, and whether it is done
274292
type TodoListItem = [string, boolean];
275293

276-
const chores: TodoListItem[] = [["read a book", true], ["done dishes", true], ["take the dog out", false]];
294+
const chores: TodoListItem[] = [
295+
["read a book", true],
296+
["done dishes", true],
297+
["take the dog out", false],
298+
];
277299
```
278300

279301
Yes, you could use an object for each item in this example, but tuples are there when it fits your needs.

0 commit comments

Comments
 (0)