Object to extrapolate keys from.
Array of keys that are typed for the specified dict
.
const value = { a: 1, b: 2, c: 3 };
const untypedKeys = Object.keys(value);
for (const key of untypedKeys) {
// This will throw a TypeScript error:
console.log(value[key]);
}
const typedKeys = keysOf(value);
for (const key of typedKeys) {
// This will *not* throw a TypeScript error:
console.log(value[key]);
}
Gets the keys of the specified
dict
as an array that won't throw a TypeScript error if you try to loop through them and access values from the correspondingdict
.Only use this function when you know that the return value of
Object.keys
will always correspond to the keys of the specifieddict
and doesn't contain any extra keys (which is probably the case most of the time if you're using plain JS objects).