我在typescript Playground中有一个演示
const C = {
METHOD: {
'1': 2,
'2': 2,
'3': 3
},
CCSIGNFLAG: {
'4': 4,
'5': 5,
'6': 6
}
};
interface IKey {
method: '123123123';
ccSignFlag: '2222';
[key: string]: string;
}
interface Ivalue {
method: '1' | '2' | '3';
ccSignFlag: '4' | '5' | '6';
[key: string]: string;
}
function test<T extends keyof IKey>(field: T, value: Ivalue[T]) {
switch (field) {
case 'method':
return C['METHOD'][value];
}
}
test('ccSignFlag', '4');
显示错误:Type 'Ivalue[T]' cannot be used to index type '{ '1': number; '2': number; '3': number; }'
我希望第一个参数约束第二个参数的输入
我该怎么办?