These notes help to aid my short term memory.
Installing NPM and Node.js via a package manager
Installing NPM and Node on Ubuntu Linux
$ sudo apt update
$ sudo apt install nodejs npm
Installing NPM and Node on macOS with Homebrew
$ brew install node
Checking your version of npm and Node.js
$ node -v
$ npm -v
npm install -g typescript
- Linux
sudo npm install -g typescript
$ npm install typescript --save-dev
- Checking your TypeScript version
$ tsc -v
- a type is low level
- types are closed
- types cannot be augmented
- types can be composed into a new type
type ToDoListItem = {
title: string;
completedDate: Date | null;
}
type ToDoList = {
todos: ToDoListItem[];
}
type CalendarEvent = {
title: string;
start: Date;
end: Date;
}
type Calendar = {
events: CalendarEvent[];
}
type AppState = ToDoList & Calendar & {
modified: Date;
}
- an interface is high level
- interfaces are open
- interfaces can be augmented
- interfaces can be merged and remain the same interface
- interfaces can implement multiple interfaces
- A simple union:
type Union = "X" | "Y" | "Z";
- A union type describes a value that can be one of several types. We use the vertical bar ( | ) to separate each type, so number | string | boolean is the type of a value that can be a number , a string , or a boolean.
enum Direction {
Up = 1,
Down,
Left,
Right,
}
- classes are high level
- a class can implement interfaces