export type OptionsToType<T extends Array<{ name: Array<string>, type: keyof TypeMapping }>>
= { [K in T[number]['name'][0]]: TypeMapping[Extract<T[number], { name: K }>['type']] }
export class CliParser<T> {
opts: OptionsToType<T>;
constructor() {
}
}
I get this error:
Does anyone know how to fix this one?
Since T
can be any type on CliParser
, it is too broad for OptionsToType
. You can limit it by doing:
export class CliParser<T extends Array<{ name: Array<string>, type: keyof TypeMapping }>> {
opts: OptionsToType<T>;
constructor() {
}
}
Definitely a little ugly. You may want to make Array<{ name: Array<string>, type: keyof TypeMapping }>
its own type.