Typescript Flashcards
var, let, const
var is function scoped
let & const is block scoped
var width:number = 100;
let height:number = 200;
const key:string = ‘abc123’;
scope of var
function
scope of let
block scope
scope of const
block scope
Basic types / Non-Basic-types
boolean number string numer[] or Array enum --------- any never void
initialize an enum
Zero-Index
enum Color {Red, Green, Blue};
let c: Color = Color.Green;
initialize an Array
let aArray: number[] = [1, 2, 3];
let aGenericArray: Array = [4,5,6];
never
never is used when a function never returns. e.g. it’s in a loop or always throws an exception.
Modifier
public
protected
private
readonly
Duck Typing
Compiler kann den Type selbst ableiten
Fat Arrow Function
(param1, param2, …, paramN) => expression
let sum = (x: number, y: number): number => { return x + y; }
Generic example
interface Identity { id: string; }
class Movie implements Identity { id: string; }
function getAsync(arg: T): Promise { return fetch(`/api/${arg.id}`) .then((response: Response) => >response.json()); }
Diamond Operator
<>