Object to union sequence

admin

typescript

другие самплы
const a = {
    a: 1,
    b: 2
} as const

type ToSequence<FieldKeys extends string, Result extends number[] = []> = {
    [Key in FieldKeys]: Exclude<FieldKeys, Key> extends never ? [...Result, Result['length']] : ToSequence<Exclude<FieldKeys, Key>, [...Result, Result['length']]>;
}[FieldKeys];

let e: ToSequence<keyof typeof a> = [0, 1]
let en: ToSequence<keyof typeof a>[number]  // 0 | 1
(ваш голос учтен)

Прикрепить файл