-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TS "Optional Properties" accepts "undefined" as a value when it shouldn't... #57479
Comments
This is working as intended and why And before the question comes up: this is intentionally not part of the |
I may have missed it (I think I started TS with 4.3)...
Then shouldn't it be an opt-out flag (when strict is specified), instead of an opt-in ? I'm gonna re-read this page. |
There's always a blog post for every release. They usually announce it on Twitter and Facebook too (probably more), but no newsletter. Choose your poison. The website also contains the documentation for every release.
|
You can subscribe to github releases, they have blog posts attached |
In the documentation, it isn't clear what that "strict mode family" flags are. |
Oh thanks, good idea indeed. |
The ones listed under "related". Each flag also mentions the default being |
Thanks, I didn't even noticed it. With that, I think I can close this issue. |
π Search Terms
Optional Properties accept undefined
π Version & Regression Information
β― Playground Link
Playground Link
π» Code
π Actual behavior
In JS, there is a difference in behavior between properties that :
undefined
when accessed.undefined
as a value.TS enables to declare a property optional with the "?" symbol (so normally corresponding to case 1.). However, this notation also allows case 2., which shouldn't be the case:
π Expected behavior
When assigning a value to a type with optional fields, TS should forbid
undefined
values except if explicitly authorized :Additional information about the issue
I get this would likely be a breaking change... but this is a bug.
Maybe a flag or a way to change TS behavior on this matter could help keeping retro-compatibility ?
The text was updated successfully, but these errors were encountered: