-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathsingle-key-object.d.ts
More file actions
28 lines (21 loc) · 737 Bytes
/
single-key-object.d.ts
File metadata and controls
28 lines (21 loc) · 737 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
import type {IsEmptyObject} from './empty-object.d.ts';
import type {If} from './if.d.ts';
import type {IsUnion} from './is-union.d.ts';
/**
Create a type that only accepts an object with a single key.
@example
```
import type {SingleKeyObject} from 'type-fest';
declare function someFunction<T>(parameter: SingleKeyObject<T>): void;
someFunction({value: true});
// @ts-expect-error
someFunction({value: true, otherKey: true});
// Error: Argument of type '{value: boolean; otherKey: boolean}' is not assignable to parameter of type 'never'.ts(2345)
```
@category Object
*/
export type SingleKeyObject<ObjectType> =
IsUnion<keyof ObjectType> extends true
? never
: If<IsEmptyObject<ObjectType>, never, ObjectType>;
export {};