type-fest/source/writable-keys-of.d.ts
2025-11-30 04:44:57 +07:00

35 lines
712 B
TypeScript

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 {};