-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18-utility-types.ts
56 lines (40 loc) · 1.38 KB
/
18-utility-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
type Client = {
name: string;
budget: number;
contracts: {
id: string;
volume: number;
}[];
accountId: string;
description: string;
lastLoginDate?: Date;
};
// some (only picked) examples of utility types
// ============== pick only selected types
type DisplayClient = Pick<Client, 'name' | 'description'>;
declare const displayClient: DisplayClient;
// ============== omit only selected types
type ClientWithoutDisplay = Omit<Client, 'name' | 'description'>;
declare const clientWithoutDisplay: ClientWithoutDisplay;
// ============== client with all fields optional - nice for stuff like drafts
type OptionalClient = Partial<Client>;
declare const optionalClient: OptionalClient;
// ============== make all fields required
type RequiredClient = Required<Client>;
declare const requiredClient: RequiredClient;
type InvoiceType = 'internal' | 'external' | 'other';
type AllInvoicesType = InvoiceType | 'all';
type AfterExclude = Exclude<AllInvoicesType, 'internal' | 'external'>; // - internal, - internal
// ============== NOW, FUNCTIONS ========================
const addClient = (
client: Client,
endpoint: string,
method: 'POST' | 'PUT'
): Promise<{ isSuccessful: boolean }> => {
return Promise.resolve({
isSuccessful: true,
});
};
type ReturnFromAddClient = ReturnType<typeof addClient>;
type AddClientParams = Parameters<typeof addClient>;
export {};