【发布时间】:2019-04-01 14:19:19
【问题描述】:
我已经开始学习打字稿了。我确信可能会有与此类似的票证,但想快速了解一下。
i have keys
type keys = 'a' | 'e' | 'i' | 'o' | 'u';
I want these to restrict the possible a keys in an object
{
numbers : number;
symbols : string;
[key : keys] : string | number | boolean;
}
但是我得到了这个错误An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
所以我尝试了
{
numbers : number;
symbols : string;
[key in keys] : string | number | boolean;
}
但我从 TSLint 得到了another error。
我希望如果有人可以通过示例帮助我解决这些问题,它们为什么以及如何变化?请和解决方案。
我想要的结果是
key with only values of a, e, i, o, u and these Keys can have any of the string, number, boolean types of values.
【问题讨论】:
标签: javascript typescript type-conversion