UNPKG

667 BTypeScriptView Raw
1import type {WritableKeysOf} from './writable-keys-of';
2
3/**
4Creates a type that represents `true` or `false` depending on whether the given type has any writable fields.
5
6This is useful when you want to create an API whose behavior depends on the presence or absence of writable fields.
7
8@example
9```
10import type {HasWritableKeys, WritableKeysOf} from 'type-fest';
11
12type UpdateService<Entity extends object> = {
13 removeField: HasWritableKeys<Entity> extends true
14 ? (field: WritableKeysOf<Entity>) => Promise<void>
15 : never
16}
17```
18
19@category Utilities
20*/
21export type HasWritableKeys<BaseType extends object> = WritableKeysOf<BaseType> extends never ? false : true;