path | title |
---|---|
/learnings/javascript_typescript_compiler |
Learnings: Javascript: Typescript: Compiler |
- Typescript Compiler
- [BOOKNOTES]:
“sealed” or “precise” type, and it cannot be expressed in TypeScript’s type system. Like it or not, your types are “open.”
- From: Effective Typescript
- [BOOKNOTES]:
Some constructs introduce both a type (which is not available at runtime) and a value (which is). The class keyword is one of these.
- From: Effective Typescript
- [BOOKNOTES]:
When you assign an object literal to a variable or pass it as an argument to a function, it undergoes excess property checking.
-
From: Effective Typescript
-
[BOOKNOTES]:
When you assign an object literal to a variable with a declared type, TypeScript makes sure it has the properties of that type and no others:
- From: Effective Typescript
- [TODO]: wite me
- [BOOKQUOTE]:
There are some situations where you can leave the type annotations off of function parameters, too. When there’s a default value, for example:
- From: Effective Typescript
check out the eslint rule no-inferrable-types
- [BOOKQUOTE]:
unknown is appropriate whenever you know that there will be a value but you don’t know its type
- from: Effective Typescript
- [BOOKQUOTE]:
Because x cannot be reassigned, TypeScript is able to infer a narrower type without risk of inadvertently flagging errors on subsequent assignments.
- From: Effective Typescript
- [BOOKQUOTE]:
When you annotate the return type, it keeps implementation errors from manifesting as errors in user code.
-
From: Effective Typescript
-
[BOOKQUOTE]:
This is a good reason to consider including explicit return type annotations, even when the return type can be inferred. It prevents an any type from “escaping.”
- from: Effective Typescript