Typescript 如何缩小符号变量的范围?

Typescript 如何缩小符号变量的范围?,typescript,Typescript,当有一个通用符号时,为什么一个普通的等式缩小不起作用 declare const sy: unique symbol; declare const x: symbol; declare const o: { [sy]: number }; if (x === sy) { o[x]; // x is still symbol, therefore this errors } 我希望它的行为类似于任何其他情况,并被缩小为sy的类型,因为每个唯一符号都有一个完全独立的标识,没有两个唯一符号

当有一个通用符号时,为什么一个普通的等式缩小不起作用

declare const sy: unique symbol;
declare const x: symbol;
declare const o: { [sy]: number };

if (x === sy) {
    o[x]; // x is still symbol, therefore this errors
}

我希望它的行为类似于任何其他情况,并被缩小为sy的类型,因为每个
唯一符号
都有一个完全独立的标识,没有两个
唯一符号
类型可以相互分配或比较。比较两个独特的符号是没有意义的,因为它们总是不同的。如果(1==0)(产生相同的错误),则类似于执行
。但是,我不是在比较两个唯一符号,而是在检查一个通用符号是否与给定的唯一符号相同。
unique symbol
symbol
的子集,因此它应该是唯一的,
unique
只意味着它应该是常量。尝试
声明const x:typeof sy
它将引用一个
唯一符号
,但其标识与
sy
绑定。