-
-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathhas-readonly-keys.d.ts
More file actions
23 lines (17 loc) · 686 Bytes
/
has-readonly-keys.d.ts
File metadata and controls
23 lines (17 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import type {ReadonlyKeysOf} from './readonly-keys-of.d.ts';
/**
Creates a type that represents `true` or `false` depending on whether the given type has any readonly fields.
This is useful when you want to create an API whose behavior depends on the presence or absence of readonly fields.
@example
```
import type {HasReadonlyKeys, ReadonlyKeysOf} from 'type-fest';
type UpdateService<Entity extends object> = {
removeField: HasReadonlyKeys<Entity> extends true
? (field: ReadonlyKeysOf<Entity>) => Promise<void>
: never;
};
```
@category Utilities
*/
export type HasReadonlyKeys<BaseType extends object> = ReadonlyKeysOf<BaseType> extends never ? false : true;
export {};