对于以下代码:
const x = {
a: 'c',
b: 'd'
};
const y = {
[x.a]: 'e',
}
生成的类型是:
typeof x -> {
a: string,
b: string
}
typeof y -> {
[x: string]: string
}
期望类型:
typeof y -> {
c: string
}
SO上的类似issue具有此处不相关的解决方案
[在Github上找到了报告的issue,该消息说这是固定的,但是不起作用]
对于以下代码:const x = {a:'c',b:'d'}; const y = {[xa]:'e',}生成的类型为:typeof x-> {a:字符串,b:字符串} typeof y-> {[x:字符串]:...
typeof x.a
实际上是一个字符串。在此,x是常数,但是x.a
的值可以更改为任何字符串值。