News for hackers. Stuff that matters.
Re:All JavaScript and TypeScript features of the last 3 year... by maxpowa on Thursday March 09, 2023 @11:47AM (#35083310)
WRT Enum as key in object:

  enum TestEnum {
    Fizz = 0,
    Buzz,
    Bar,
    Baz
  }

  type EnumKeyedObject = Record<TestEnum, string>;

  type EnumKeyedObjectAlt = { [P in TestEnum]: string };
Re:All JavaScript and TypeScript features of the last 3 year... by mjhay on Thursday March 09, 2023 @12:50PM (#35084208)
That's still awkward and confusing for what would be one of the most common use-cases, if it were less awkward.
Re:All JavaScript and TypeScript features of the last 3 year... by throwanem on Thursday March 09, 2023 @02:52PM (#35085754)
How would you simplify the syntax here?
Re:All JavaScript and TypeScript features of the last 3 year... by itslennysfault on Friday March 10, 2023 @11:17AM (#35096376)
I'd like to be able to just do...

    type UserType = 'default' | 'admin' | 'manager';

    interface UserTypeCounts {
        [key: UserType]: number
    }
Not the best example, but it gets the point across. When you do this it says the key must be a string type which it actually is. It's just a string limited to specific values.

Yes, I could do an interface with explicitly named keys instead, but if that type (or enum) could have dozens of possible values it's annoying to duplicate it.