-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
33 lines (27 loc) · 771 Bytes
/
Copy pathtypes.ts
File metadata and controls
33 lines (27 loc) · 771 Bytes
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
/**
* generic utility types for python-utils-73 data handling
*/
export type Nullable<T> = T | null | undefined;
export type DeepPartial<T> = {
[P in keyof T]?: T[P] extends (infer U)[]
? DeepPartial<U>[]
: T[P] extends object
? DeepPartial<T[P]>
: T[P];
};
export interface DataEnvelope<T> {
payload: T;
timestamp: number;
metadata: Record<string, unknown>;
}
export const isDefined = <T>(value: Nullable<T>): value is T => {
return value !== null && value !== undefined;
};
export const wrapData = <T>(data: T, extra: Record<string, unknown> = {}): DataEnvelope<T> => ({
payload: data,
timestamp: Date.now(),
metadata: extra,
});
export const extractValue = <T, K extends keyof T>(obj: T, key: K): T[K] => {
return obj[key];
};