You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If Object.keys() is passed a Record, the returned array should infer the type based on the type of the Record. Please see example if this is unclear.
🔍 Search Terms
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
object.keys object.keys() record string
✅ Viability Checklist
My suggestion meets these guidelines:
[ x ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
[ x ] This wouldn't change the runtime behavior of existing JavaScript code
[ x ] This could be implemented without emitting different JS based on the types of the expressions
[ x ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
It's a common pattern for myself in React applications to create a Record which maps some enum (by that I mean a string union) to another value, then to use Object.keys() to iterate over the keys of that object and use the key to access the object. The problem is when accessing the object using one of its keys, the key is of type string when it should be guaranteed to be of the type of the index specified for the Record passed into Object.keys()
The text was updated successfully, but these errors were encountered:
Suggestion
If Object.keys() is passed a Record, the returned array should infer the type based on the type of the Record. Please see example if this is unclear.
🔍 Search Terms
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
object.keys object.keys() record string
✅ Viability Checklist
My suggestion meets these guidelines:
📃 Motivating Example
Note: Make some kind of change (add a new line at the end for example) to tsconfig.json and save it to see the actual typescript error/red squiggle, it doesn't appear by default
https://stackblitz.com/edit/typescript-tj8tyt?file=index.ts&view=editor
💻 Use Cases
It's a common pattern for myself in React applications to create a Record which maps some enum (by that I mean a string union) to another value, then to use Object.keys() to iterate over the keys of that object and use the key to access the object. The problem is when accessing the object using one of its keys, the key is of type string when it should be guaranteed to be of the type of the index specified for the Record passed into Object.keys()
The text was updated successfully, but these errors were encountered: