How to use strongly-typed version of Object.keys
25 January 2024 (Updated 25 January 2024)
Before:
Object.keys(yourObj) // returns string[] even if you provided a type definition for yourObj
After:
Run npm i ts-extras
and then use like this:
import { objectKeys } from 'ts-extras'
objectKeys(yourObject) // returns ProperTypeOfYourObj[]
Tagged:
TypeScript
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment