File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -102,19 +102,19 @@ const c:unique symbol = b; // 报错
102
102
103
103
上面示例中,unique symbol 类型(变量` a ` )赋值给 symbol 类型(变量` b ` )是可以的,但是 symbol 类型(变量` b ` )赋值给 unique symbol 类型(变量` c ` )会报错。
104
104
105
- unique symbol 类型的一个作用,就是用作属性名,这可以保证不会跟其他属性名冲突。如果要把某一个特定的 Symbol 值当作属性名,那么它的类型只能是 unique symbol,不能是 symbol。
105
+ unique symbol 类型的一个作用,就是用作属性名,这可以保证不会跟其他属性名冲突。在 5.8.3 版本之前, 如果要把某一个特定的 Symbol 值当作属性名,TypeScript 只允许它的类型是 unique symbol,不能是 symbol,5.8.3 版本之后没有了这个限制 。
106
106
107
107
``` typescript
108
108
const x: unique symbol = Symbol ();
109
109
const y: symbol = Symbol ();
110
110
111
111
interface Foo {
112
112
[x ]: string ; // 正确
113
- [y ]: string ; // 报错
113
+ [y ]: string ; // 5.8.3 版本之前报错
114
114
}
115
115
```
116
116
117
- 上面示例中,变量` y ` 当作属性名,但是` y ` 的类型是 symbol,不是固定不变的值,导致报错 。
117
+ 上面示例中,变量` y ` 当作属性名,但是` y ` 的类型是 symbol,不是固定不变的值,5.8.3 版本之前会报错,之后就不会 。
118
118
119
119
` unique symbol ` 类型也可以用作类(class)的属性值,但只能赋值给类的` readonly static ` 属性。
120
120
You can’t perform that action at this time.
0 commit comments