有没有办法限制,keyof T以便它只接受某种类型的键?假设如下:
interface Something {
id: number;
name: string;
value1: FancyType;
value2: FancyType;
value3: FancyType;
}
function someFunction(key: keyof Something) {
// do something to a FancyType
}
Run Code Online (Sandbox Code Playgroud)
someFunction会接受id | name | value1 | value2 | value3,有没有办法将它限制为类型的键FancyType,即value1 | value2 | value3?
typescript ×1