string, number, any, never, array[], boolean, tuple, enum, void, null, undefined, Object
can assert that a type is correct thing as Type
var is JS madness
let is a sane mutable variable
const is an un-assignable variable
arrays and tuples and objects can be destructured into distinct named variables
spread operator will combine arrays or objects
color? = stringthis for member accessclass Dog extends Animalreadonly properties must be initialized at declaration or in the constructorfunction add(x: number, y: number): number {(x: number, y: number) => number arg names are not matchedcolor?: string, or defaulted color = "red"...restOfName: string[]f(this: Something, .. )Normally,
thisis set when the function is called. Arrow functions capture thethiswhere the function is created rather than where it is invoked.
function() { becomes () => {function something<T>(arg: T): Tx is compatible with y if y has at least the same members as x
Person & Serializable & Loggable has all the members of all three types
number | string one type or the other
Can only access members that are common to the union
Restrict something to a certain subtype in a particular scope
Custom type guards
typeof
instanceof like typeof but looks at the constructor function
Can use flag —strictNullChecks to prevent any variable from being assigned null, unless you use a union type containing null.
These create a new name for an existing type.
Specify the exact value a string must have. Other strings will not be able to be assigned. Useful when combined with union types. Same things exists with numbers
T extends U ? X : Y
Choose the type based on some condition
Lots more going on here.
for (let x of list) // loops over the values of list
for (let i in list) // loops over the keys of list
"of" can only be used on Symbol.iterator things, while "in" can be used on any object to enumerate it’s properties
declare module to create the types for things that already exist/// <reference path="Validation.ts" /> is needed to have multi-file namespacesDon’t mix the two too much. Node uses modules almost exclusively
If you define something, ie an interface, multiple times, ts will combine the members from both. You can merge a class and a namespace to get the effect of an inner class.
An xml like language that compiles to js, used largely in react. Need .tsx extension
@decorator where decorator refers to a function decorator(target) that will do something importantCompiler directives of form /// <reference path="..." />
Only valid at top of file
Partial<T>: new type has all properties of T, but they are optionalReadonly<T>: new type has all properties of T, but they are readonlyRecord<K,T>:Pick<T,K>: new type by picking the properties K from TOmit<T,K>: opposite of pickExclude<T,U>Extract<T,U>NonNullable<T>: removing null and undefined from TReturnType<T>: The return type of TInstanceType<T>: The instance type of a constructor functionRequired<T>: new type has all properties of T, but they are requiredThisType<T>