-
-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathwritable-keys-of.d.ts
More file actions
34 lines (25 loc) · 712 Bytes
/
writable-keys-of.d.ts
File metadata and controls
34 lines (25 loc) · 712 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
34
import type {ReadonlyKeysOf} from './readonly-keys-of.d.ts';
/**
Extract all writable keys from the given type.
This is useful when you want to create a new type that contains writable keys only.
@example
```
import type {WritableKeysOf} from 'type-fest';
type User = {
name: string;
surname: string;
readonly id: number;
};
type UpdateRequest<Entity extends object> = Pick<Entity, WritableKeysOf<Entity>>;
const update1: UpdateRequest<User> = {
name: 'Alice',
surname: 'Acme',
};
```
@category Utilities
*/
export type WritableKeysOf<Type extends object> =
Type extends unknown // For distributing `Type`
? Exclude<keyof Type, ReadonlyKeysOf<Type>>
: never; // Should never happen
export {};