It might be advisable to share that there’s a reason why Object.keys is always an array of strings, and that’s that the Typescript team feels that you have no way of knowing that an object will have exactly the keys that are on the interface. In reality, it’s very common for objects to have more properties at runtime than they due at compile time because of Typescript’s structural subtyping.
So in a sense, your Object keys alternative implies that there will be a definitive set of string literals in the union, but technically it could be an infinite number (hence the Typescript team just calling it a string).
It might be advisable to share that there’s a reason why Object.keys is always an array of strings, and that’s that the Typescript team feels that you have no way of knowing that an object will have exactly the keys that are on the interface. In reality, it’s very common for objects to have more properties at runtime than they due at compile time because of Typescript’s structural subtyping.
So in a sense, your Object keys alternative implies that there will be a definitive set of string literals in the union, but technically it could be an infinite number (hence the Typescript team just calling it a
string
).Good point. I didn't know myself 😅