mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-15 22:52:36 +03:00
18 lines
876 B
TypeScript
18 lines
876 B
TypeScript
export type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;
|
|
|
|
/**
|
|
A strongly-typed version of `Object.keys()`.
|
|
This is useful since `Object.keys()` always returns an array of strings. This function returns a strongly-typed array of the keys of the given object.
|
|
- [Explanation](https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript)
|
|
- [TypeScript issues about this](https://github.com/microsoft/TypeScript/issues/45390)
|
|
@example
|
|
```
|
|
const stronglyTypedItems = objectKeys({a: 1, b: 2, c: 3}); // => Array<'a' | 'b' | 'c'>
|
|
const untypedItems = Object.keys(items); // => Array<string>
|
|
```
|
|
@category Improved builtin
|
|
@category Type guard
|
|
*/
|
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
export const objectKeys = Object.keys as <Type extends object>(value: Type) => Array<ObjectKeys<Type>>;
|