Typescript compiler handling of optional class properties seems to have changed from es2021
to es2022
.
class A {
a?: string
b?: string
constructor() {
this.b = 'asd'
}
}
console.log(new A())
with tsconfig target=es2021
results in
A: {
"b": "asd"
}
with tsconfig target=es2022
results in
A: {
"a": undefined,
"b": "asd"
}
I cannot find any documentation regarding this change. Is this really intended behaviour and why?
It is easy to reproduce in ts playground by changing TS Config->Target
The difference is
useDefineForClassFields
:TS Documentation