exactOptionalPropertyTypes
does not apply to constructor parameters
#48952
Labels
Working as Intended
The behavior described is the intended behavior; this is not a bug
Bug Report
🔎 Search Terms
exact, optional, property, types, constructor, parameters, arguments, undefined, ?
🕗 Version & Regression Information
4.4 & above (including the latest nightly, v4.7.0-dev.20220504)
exactOptionalPropertyTypes
was added in 4.4⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Only the property which is defined on the class itself reports as an error, when
undefined
is assigned to them.The types on the class is incorrect as well.
In the JS emitted, one can see that an assignment is made regardless if a parameter is passed into it.
While typescript's error is consistent with the outputted code, this may not be the expected behaviour when
exactOptionalPropertyTypes
is enabled. Related: #47350.🙂 Expected behavior
Properties defined in both styles should report an error, when
undefined
is assigned to them.The types on the class should have their behaviours matched as well.
The JS emitted, while I'm not sure how viable it is, should only assign when a parameter is passed in.
The text was updated successfully, but these errors were encountered: