Study Notes of Typescript
Ref Link: https://paper.dropbox.com/doc/Intro-to-TypeScript-DLvvIv9jdt2XdnawLK9AX
Basic types and variable declarations
const study: string = ‘study’;
Primitives and Non-primitives
Primitives
- boolean
- number
- string
- null
- undefined (sometimes annotated as void)
Non-primitives
I like to think of composite types as data structures that can “contain” other types.
- Array - e.g. [3, 1, 4]
- Object, aka “plain object” - e.g. { key: “value” }
- An instance of a class - e.g. new Date()
- Function - e.g. (a, b) => a + b
Typing function arguments and return types
you can add types for function parameter and return type
function add(x: number, y: number): number {
return x + y;
}