如何获得数组的所有可能索引作为数字联合类型?
Expected result a number union type:
type VoiceSettings = {
similarityLevel: 0 | 1 | 2 | 3 | 4 | 5;
stabilityLevel: 0 | 1 | 2 | 3 | 4;
}
Actual result:
type VoiceSettings = {
similarityLevel: "0" | "1" | "2" | "3" | "4";
stabilityLevel: "0" | "1" | "2" | "3" | "4";
}
Code:
const VALUES_MAP = {
similarityLevel: [0, 15, 30, 50, 75, 90],
stabilityLevel: [15, 30, 60, 75, 90],
} as const;
type ValuesTypes = keyof typeof VALUES_MAP;
type VoiceSettings = {
[key in ValuesTypes]: Exclude<keyof (typeof VALUES_MAP)[ValuesTypes], keyof []>;
};