persona-community-5/.pnpm-store/v3/files/76/5f76bfcd69ed748fc06699f9fa611cf00ea4440d83bd66365f42da91ab796cde69d7d758548e5ff29377dd8d7d9cc28ef5e1e5514508c511eeeb4c744d840c
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

34 lines
848 B
Plaintext

import type {IsEqual} from './is-equal';
/**
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';
interface 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<T> =
T extends unknown // For distributing `T`
? (keyof {
[P in keyof T as IsEqual<{[Q in P]: T[P]}, {readonly [Q in P]: T[P]}> extends false ? P : never]: never
}) & keyof T // Intersect with `keyof T` to ensure result of `WritableKeysOf<T>` is always assignable to `keyof T`
: never; // Should never happen