mrt*_*rsn 2 typescript tsc tsconfig es2022
Typescript 编译器对可选类属性的处理似乎已从 更改es2021为es2022。
class A {
a?: string
b?: string
constructor() {
this.b = 'asd'
}
}
console.log(new A())
Run Code Online (Sandbox Code Playgroud)
与 tsconfig target=es2021结果
A: {
"b": "asd"
}
Run Code Online (Sandbox Code Playgroud)
与 tsconfig target=es2022结果
A: {
"a": undefined,
"b": "asd"
}
Run Code Online (Sandbox Code Playgroud)
我找不到有关此更改的任何文档。这真的是有意的行为吗?为什么?
通过更改 TS Config->Target可以轻松在 ts Playground中重现
| 归档时间: |
|
| 查看次数: |
262 次 |
| 最近记录: |