type A = 'a';
type B = 'b';
type C = 'c';
interface List {
a: A;
b: B;
c: C;
}
const myFunc = (name: keyof List) => {
type MyType = List[name];
return 'something' as MyType;
// 如何实现 myFunc('a') 返回的是A类型,myFunc('b')返回的是B类型
// 这样写会报错:
// Type 'name' cannot be used as an index type
}