-
Notifications
You must be signed in to change notification settings - Fork 1
/
01 - basic types.ts
63 lines (52 loc) · 1.16 KB
/
01 - basic types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// supported types
export type JsTypes =
| string
| boolean
| number
| symbol
| object
| null
| undefined
| Date
| Function
export type SpecialTypes = any | void | never | unknown
// type aliases
export type Name = string
export type Age = number
export type Email = string
export type PhoneNumber = number
export type WithAge = { age: Age }
export type GetGreeting = (greetee: Person) => string
export type Callback<R> = (error: any, result: R) => void
// enums
export enum Title {
Bachelor,
Master,
PhD
}
// union type
export type Job = 'Software Developer' | 'Rocket Scientist'
export type ContactInfo = Email | PhoneNumber
// interfaces
export interface IHaveNames {
firstname: Name
lastname: Name
}
// with readonly property
export interface IHaveAMiddlename {
readonly middlename: Name
}
// with generic type parameter
export interface IHaveJob<T extends Job> {
job: T
}
// with optional property
export interface IMayBeEmployed {
employer?: string
}
// intersection type
export type Person = IHaveNames & WithAge
// keyof operator
export type Keys<T> = keyof T
// unsatisfiable type definition
type StringAndNumber = string & number