type-fest
Version:
A collection of essential TypeScript types
32 lines (23 loc) • 631 B
TypeScript
/**
Represents an object with `unknown` value. You probably want this instead of `{}`.
Use case: You have an object whose keys and values are unknown to you.
@example
```
import type {UnknownRecord} from 'type-fest';
function toJson(object: UnknownRecord) {
return JSON.stringify(object);
}
toJson({hello: 'world'});
//=> '{"hello":"world"}'
function isObject(value: unknown): value is UnknownRecord {
return typeof value === 'object' && value !== null;
}
isObject({hello: 'world'});
//=> true
isObject('hello');
//=> false
```
@category Type
@category Object
*/
export type UnknownRecord = Record<PropertyKey, unknown>;