我试图在运行时获取一个包含在字符串数组中定义的属性的类型。 Typescript类型系统有可能做到这一点吗?
const props = ["a", "b", "c"];
function f(props): <????> {
// ...
}
const instance = f(props);
instance.a; // ok
instance.z; // compiler error
那么如何定义结果类型?
答案 0 :(得分:0)
您可以使用映射类型将键的并集转换为对象类型(预定义的映射类型df['Score'] = df.Score.str.rstrip('.')
>>> df
ID Score
0 0 50
1 1 60
2 2 70.5
3 3 65.5
4 4 56.5.6
5 5 56.5.6.7
6 6 10
7 7 56.0
8 8 56.5.0
将达到目的)。您还需要帮助类型推断来推断Record
常量而不是字符串的字符串文字的元组类型,因为我们需要有关数组中确切保留哪些字符串的信息
props