News for hackers. Stuff that matters.
Re:All JavaScript and TypeScript features of the last 3 year... by 5Qn8mNbc2FNCiVV on Thursday March 09, 2023 @02:56PM (#35085797)
Isn't Record<EnumType, whatever> working?

Then instantiate like:

``` { [EnumType.First]: ..., [EnumType.Second]: ... } ```

Re:All JavaScript and TypeScript features of the last 3 year... by hn_throwaway_99 on Thursday March 09, 2023 @04:13PM (#35086791)
Yep, do this all the time. It's also really nice because when you define a type as

    Record<EnumType, any>
then when you are creating an instance of that Record object, it requires a key for all the EnumType values, and will fail if you forgot one. Still possible to do

    Partial<Record<EnumType, any>>
if you want the keys to be only of the EnumType, but don't require all the EnumType values to be used as a key in the Record.