相关疑难解决方法(0)

Keyof也是T型

有没有办法限制,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

10
推荐指数
2
解决办法
1111
查看次数

标签 统计

typescript ×1