const typedKeys = <O extends {}>(o: O) =>
Object.keys(o) as Array<keyof O>;
const o = {
first: 'josh',
last: 'o'
};
const keys = Object.keys(o);
type T = typeof keys[number] // string
const betterKeys = typedKeys(o);
type U = typeof betterKeys[number]; // 'first' | 'last'
Last active
February 13, 2023 18:23
-
-
Save joshwashywash/32d2f34ca29c29d5a85f8554b2af5814 to your computer and use it in GitHub Desktop.
gets keys of an object in typescript
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment