Object.keys() on a typed Object loses it's keys type
Playground with examples
How is it different than ts-extra
> objectKeys
?
- Preserves the keys type of a typed object instead of getting a union of the actual keys values (see playground)
TL;DR
/**
* A strongly-typed version of `Object.keys()`
*
* Details:
* https://gist.github.com/alexilyaev/3fe3e6e6065b9f19450ac52a11209f52
*/
export const objectKeysTyped = Object.keys as <Type extends object>(
value: Type
) => Array<keyof typeof value>;