Title: Theory / Important / CS / Programming / JS / TS
Tags: declaration seen_description todo_declaration computer_to_instruction automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html

Instruction: tsc foo.ts
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Effect: Compile foo.ts to foo.js in ES3 and explain the typing errors
Language: typescript

Fla: --noEmitOnError
Effect: Don't create/update the js file if there are errors
Prefix: tsc foo.ts

Question: Why does TS compile even with errors
Answer: Programmer often know bettor. Conversion from js to TS may create a lot of errors while code works
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Context: tsc foo.ts

Name: Downleveling
Definition: Transforming code into code doing the same thing in an older version of the language
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html

Fla: --target foo
Effect: Compile to version foo of javascript/ecmascript
Prefix: tsc

Fla: --strict
Effect: Make TS compiler strict.
Prefix: tsc

Variable: tsconfig.json
Meaning: Configuration used for compilation of ts
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Context: tsc
Language: typescript

Question: What is the type when annotation is missing
Answer: If variable is initalized with a value, then the type of this value
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Context: tsc
Answer2: Otherwise any, unless --noImplicitAny in which case it fails

Fla: --strictNullChecks
Effect: Ensure null and undefined are really checked
Prefix: tsc

Fla: --noImplicitAny
Effect: Do not use Any as type when it is not known
Prefix: tsc

Name: Primitive type
Definition: String
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Context: TypeScript
Definition2: Number
Conjdef: All of
Definition3: Boolean
Definition4: BigInt (Starting in ES2020)
Definition5: symbol (Starting in ES2020)
Definition6: undefined
Definition7: null

Typ: Array<T> or T[]
Meaning: An array whose elements' type is T
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Language: typescript
Variables: T a type

Typ: any
Meaning: Union of all other types. Has all properties, is callable, etc... Equivalent to top for functional languages
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Language: typescript
Variables: T a type

Instruction: let foo: T = value
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Meaning: Declare foo having type T and being initialized at value
Language: typescript
Variables: T a type

Instruction: function foo(
  var1: T1,
  ...,
  varn: Tn
) {
  bar
}
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Meaning: Declare a function foo,
  with n parameters vari of type Ti,
  executing bar
Language: typescript
Variables: T a type

Instruction: function foo(
  var1: T1,
  ...,
  varn: Tn
) :Tr{
  bar
}
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Meaning: Declare a function foo,
  with n parameters vari of type Ti,
  returning a value of type Tr executing bar
Language: typescript
Variables: T a type

Question: What is the default type returned by functions
Answer: void if there is no return instruction
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Context: TypeScript
Answer2: Guessed from function code (be more specific ?)

Question: What is the default type of function parameter
Answer: For anonymous function, guessed from context if possible
Page: https://www.typescriptlang.org/docs/handbook/2/basic-types.html
Context: TypeScript
Answer2: any, unless --noImplicitAny

Name: Contextual typing
Definition: Typing done automatically using the context
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Context: TypeScript

Typ: {PROP1: T1, ..., PROPn: Tn}
Meaning: Objects with at least properties PROPi of type Ti
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Language: TypeScript

Typ: T1|T2
Meaning: Either of type T1 or T2
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Language: TypeScript
Name: Union type

Instruction: if (checking whether foo has type Ti) {
  foo
} else {
  bar
}
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Effect: Either foo where v is assumed to have type Ti or bar where it is assumed to have type T1 | ... | Tn but not Ti
Language: TypeScript
Variables: v: T1|...|Tn
Name: Narrowing

Instruction: typeof v === "T"
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Language: TypeScript
Returns: Whether the type of v is T
Variables: v a variable

Instruction: Array.isArray(v)
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Language: TypeScript
Returns: Whether v is an array
Variables: v a variable

Question: What can be done with a union type?
Answer: Either narrow it
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Variables: v a variable
Context: Typescript
Answer2: Or use a property that all types of the union have

Instruction: type foo = bar;
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Meaning: Define a new type named foo as an abbreviation for bar
Language: Typescript
Variables: v a variable

Instruction: interface foo {
  PARAM1: T1;
   ...
   PARAMn: Tn
}
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Meaning: Define a new type named foo as an abbreviation for object with parameter PARAMi and type Ti
Language: Typescript
Variables: v a variable

Instruction: interface foo extends bar1, ..., barn {
  PARAM1: T1;
   ...
   PARAMn: Tn
}
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Meaning: Define a new type named foo, containing all properties of interfaces bari as an abbreviation for object with parameter PARAMi and type Ti
Language: Typescript
Variables: v a variable

Typ: T1 & T2
Meaning: Type of elements that are simultaneously T1 and T2
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Language: Typescript
Variables: v a variable

Instruction: x as y
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Language: typescript
Returns: x
Variables: v a variable
Abbreviation: <y>x
Assuming: The inferred type of x is either less or more specific than y, but at least should be comparable
Typ: y
Name: Type assertion

Question: How to state that x has type T if its inferred type is not comparable to T?
Answer: (x as any) as T
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html

Typ: c
Meaning: The type whose only value is c
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Language: typescript
Context: c a constant

Question: How to create an enum
Answer: Represent each element of the enum as a string/int, and take their union as type
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Context: Typescript

Instruction: {VAR1: VAL1, ..., VARn:VALn} as const
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Language: Typescript
Returns: {VAR1: VAL1 as VAL1, ..., VARn:VALn as VALn}

Instruction: x!
Page: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Effect: Type system assume that x is neither null nor undefined
Language: Typescript
Returns: x

Name: A type guard
Definition: An assertion that a variable has a specific type
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Context: Typescript
Example: typeof var === "type"
Example2: Array.isArray(v)
Example3: x instanceof Class

Name: Type
Definition: Primitive type
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Context: Typescript
Definition2: Function
Definition3: Object
Definition4: never
Definition5: Class/prototype

Name: The declared type of a variable
Definition: The type associated to a variable by typescript. Whether it is explicitly given or guessed at initialization
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Context: Typescript

Name: control flow analysis
Definition: Analysing a variable depending on the possible path the execution can take
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Context: Typescript

Instruction: function foo(var: T|U): var is T {
  bar
}
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Meaning: Define a type predicate, where bar allow to confirm or infirm whether var is of type T
Language: typescript

Typ: never
Meaning: The type with no content
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Language: typescript
Intuition: Return type of function raising an exception

Typ: (var1: T1, ..., varn: Tn) => U
Meaning: Type of function taking n arguments, with ith parameter named vari of type Ti
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Language: Typescript

Typ: (var1: T1, ..., VARn: Tn) : U
Meaning: Type of function taking n arguments, with ith parameter named vari of type Ti
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Language: Typescript
Context: Object type
Name: type signature

Typ: new (var1: T1, ..., VARn: Tn) : U
Meaning: Type of function taking n arguments, with ith parameter named vari of type Ti, returning a new element of type U
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Language: Typescript
Context: Object type
Name: Constructor signature

Instruction: <Type>
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Meaning: Introduce a new type Type that can be used in the function arguments, return types and code
Language: Typescript
Context: Object type
Name: Type parameter

Instruction: <Type extends foo>
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Effect: Same as <Type>, but restricted to case where Type extends foo
Language: Typescript
Name: Constraints

Question: Good practice with type parameters
Answer: Avoid constraining it
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Context: Typescript
Answer2: use as few as possible
Answer3: Each parameter should appear at least twice

Instruction: x?: T
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Effect: x: T | undefined
Language: Typescript
Intuition: Optional parameters

Instruction: function foo(
  var1:T1,
  ...,
  varn:Tn
): Un;
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Meaning: Indicate that one of the valid way to call foo is with signature (
  var1:T1,
  ..., varn:Tn
): Un
Language: Typescript
Intuition: Allow to give multiple signature to a same function name

Typ: void
Meaning: return type of function not returning values
Page: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
Language: Typescript

Typ: unknown
Meaning: A type that represent any value and can't be used
Page: https://www.typescriptlang.org/docs/handbook/2/functions.html
Language: Typescript

Instruction: ...xs: T[]
Page: https://www.typescriptlang.org/docs/handbook/2/functions.html
Effect: All arguments in a call not assigned to a parameter are associated to xs and put in an array of type T
Language: Typescript
Context: function parameters

Instruction: ...xs
Page: https://www.typescriptlang.org/docs/handbook/2/functions.html
Effect: Similar as giving all content of xs as arguments of the function call
Language: Typescript
Context: function call

Instruction: {x1, ..., xn}
Page: https://www.typescriptlang.org/docs/handbook/2/functions.html
Effect: For the argument arg of the function call, assign the variable xi to arg.xi
Language: Typescript
Context: function parameter

Question: How to type parameter of an object in a destructuring pattern?
Answer: It's impossible, because foo:bar means: "Take the parameter foo of the object and assign its value to variable bar"
Page: https://www.typescriptlang.org/docs/handbook/2/objects.html
Context: Typescript

Instruction: readonly foo : bar
Page: https://www.typescriptlang.org/docs/handbook/2/objects.html
Meaning: State that the parameter foo of type bar can't be assigned after object creation
Language: Typescript
Context: interface/object type definition
Extra: Note that the value can still be modified. But not by this typescript checked code

Typ: ReadonlyArray<Type> Readonly Type[]
Meaning: Array of type Type whose content can't be changed
Page: https://www.typescriptlang.org/docs/handbook/2/objects.html
Language: Typescript

Typ: [T1,..., Tn, U1?, ..., Um]
Meaning: A tuple whose i-th element has type Ti, and n+i-th element has type Ui if it exists
Page: https://www.typescriptlang.org/docs/handbook/2/objects.html
Language: Typescript

Typ: [T1,..., Tn, ...U] where the second "..." is literally here
Meaning: A tuple whose i-th element has type Ti, and all elements after have type U
Page: https://www.typescriptlang.org/docs/handbook/2/objects.html
Language: Typescript

Typ: readonly [T1,..., Tn]
Meaning: Same as [T1,..., Tn], but whose content can't be modified
Page: https://www.typescriptlang.org/docs/handbook/2/objects.html
Language: Typescript

Instruction: fun<U1,...,Un>(vars)
Page: https://www.typescriptlang.org/docs/handbook/2/objects.html
Effect: same as fun(vars), and ensure that the i-th type parameter is interpreted as Ui
Language: Typescript
Variables: function fun<T1,...,Tn>(...) :...{...}

Instruction: ReturnType<FunType>
Page: https://www.typescriptlang.org/docs/handbook/2/objects.html
Language: Typescript
Returns: The return type of FunType
Variables: funType a function type

Instruction: typeof x
Page: https://www.typescriptlang.org/docs/handbook/2/objects.html
Language: Typescript
Returns: The type of x in a type setting, a string representing it in an execution setting

Instruction: T[param]
Page: https://www.typescriptlang.org/docs/handbook/2/objects.html
Language: Typescript
Returns: The type associated to the parameter param in T
Variables: T an object type

Instruction: T extends U? V: W
Page: https://www.typescriptlang.org/docs/handbook/2/objects.html
Language: Typescript
Returns: The type V if T extends U else W
Variables: T,U,V,W types

Instruction: <..., infer Foo, ...>
Page: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
Meaning: Introduce a type parameter Foo whose value is the type inferred at the point of the type paremetr
Language: Typescript

Page: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
Effect: T<U|V>
Language: Typescript
Returns: T<U> | T<V>

Instruction: [Property in keyof Type]: T
Page: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
Effect: Assign that the object type has all the parameters of Type, with same readonly and ? parameter but associad to type T
Language: Typescript
Context: object type definition

Instruction: readonly [Property in  Type]: T
or
+readonly [Property in  Type]: T
Page: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
Effect: Same as [Property in  Type]: T
and furthermore all properties are readonly
Language: Typescript
Context: object type definition

Instruction: -readonly [Property in  Type]: T
Page: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
Effect: Same as [Property in  Type]: T
and furthermore all properties are writeable
Language: js
Context: object type definition

Instruction: [Property in  Type]-?: T
Page: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
Effect: Same as [Property in  Type]: T
and furthermore all properties are mandatories
Language: Typescript
Context: object type definition

Instruction: [Property in  Type]?: T
or
[Property in  Type]+?: T
Page: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
Effect: Same as [Property in  Type]: T
and furthermore all properties are optional
Language: Typescript
Context: object type definition

Instruction: [key: string]: Type
Page: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
Effect: All keys of type string are associated with a value of type Type
Language: Typescript
Context: object type definition

Instruction: `foo0${T00|...|T0n0}foo1...{Tm0|...|Tmnm}foon`
Page: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html
Effect: Get extended as the union of all strings of the form
"foo0T0I0foo1...TmImfoom" for some 0<= Ij  <= ni
Language: Typescript

Instruction: class foo implements bar {...}
Page: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html
Meaning: Ensure that the class foo defined currently can be used as an object of type bar
Language: Typescript

Question: What are the constraints about deriving a class?
Answer: The derived class must satisfy the base class contract
Page: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html
Context: Typescript

Instruction: private foo
Page: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html
Effect: foo can only be accessed in C
Language: Typescript
Context: class C

Instruction: protected foo
Page: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html
Effect: foo can only be accessed in class which derives from C
Language: Typescript
Context: class C

Typ: this
Meaning: The type of the this variable. I.e. what the method was called on
Page: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html
Language: Typescript
Context: class C
Intuition: Ensure that in a derived class, this has the derived type

Instruction: abstract class foo {...}
Page: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html
Effect: The class foo's can be instanciated
Language: Typescript
Context: class C

Instruction: abstract foo(vars): T;
Page: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html
Effect: State that any non-absract class deriving current class should implement a method foo with parameters vars
Language: Typescript
Context: class C
Returns: type T
Assuming: abstract class

Name: A module
Definition: A file containing top level import/export
Page: https://www.typescriptlang.org/docs/handbook/2/modules.html
Context: Typescript

Name: A script
Definition: A ts file which is not a module
Page: https://www.typescriptlang.org/docs/handbook/2/modules.html
Context: Typescript

Question: What is a scope of a top level declaration
Answer: The module if it's in the module, or global otherwise
Page: https://www.typescriptlang.org/docs/handbook/2/modules.html
Context: Typescript

Instruction: export {};
Page: https://www.typescriptlang.org/docs/handbook/2/modules.html
Effect: Don't export anything, but consider the file as a module
Language: typescript

Extension: ts
Description: typescript
Other fields (not shown on cards):
Page: https://www.typescriptlang.org/docs/handbook/module-resolution.html