typescript - Union type as key in interface? - Stack Overflow

PHOTO EMBED

Thu Mar 31 2022 08:57:20 GMT+0000 (UTC)

Saved by @avivdaniel #javascript

export type Language = 'EN' | 'DE' | 'IT';

export interface Document {
  generic: string;
  languages: {
    [key in Language]: string[];
  }
}
content_copyCOPY

You can use a Union Type as a key in a sub-property of an Interface.

https://stackoverflow.com/questions/55023610/union-type-as-key-in-interface