Discussion on --strictOptionalProperties
#44421
Comments
|
New Errors list from last night #44427 |
|
Last night I tried updating pyright/pylance to a build of TS that included this to see how it would go. I'll try and sum up my thoughts... I'm not sure that this check is going to end up being widely usable any time soon; I get loads of messages coming from the types of libraries I don't control, especially from the LSP client library (and spec), where they treat As for trying to fix our own code, the messaging is definitely bad; I found it very hard to try and locate the actual place I needed to make the change in a large project. I ended up starting tsc in watch mode, opening a file with an error in VS Code, then I see the problems (as VSC only shows errors in open files). Then, either the related diagnostic pointed back to the declaration (so I could jump and add I'm sure it could be improved to say something like "property had a Before I gave up, I still had hundreds of errors to fix. It seemed almost random which properties I needed to change, and I was left with a number of interfaces where some properties had I'm not sure I've actually been able to find any bugs with this so far; maybe I'm too inclined to just try and stick I'm pretty surprised that this is on by default; it feels really noisy (far noisier than the not-default |
|
Is the I thought that it was supposed to just remove the |
|
I believe language features should be a right balance between exactness and usability, i.e. a health dose of pragmatism. Now, because I use the I guess the issue here stems from the fact that there are many levels of strictness, and because |
There are - set the individual flags you need. Multiple |
Fun fact: When I used to write plain JS, I did |
We've pulled in a new feature called
--strictOptionalPropertieswhich sits under the--strictfamily of flags. If we were to start TypeScript over again, we believe the behavior ofstrictOptionalPropertieswould be on by default; however, this strictness option comes at a time when the community is much more mature with lots of existing code.I've opened up this issue to discuss some broader concerns so that we can ensure that
--strictOptionalPropertiesships smoothly and so we can hear some feedback from users.Off the bat, here's a few of my own concerns:
Discoverability of the Break
A user who upgrades TypeScript with
--stricton currently has no idea why their code has broken. At best, they will get an error likeWe can do better here, which is why I've opened up #44403.
Manual Upgrade Woes
The most permissive thing to do to fix breaks from
--strictOptionalPropertiesis to tack on an| undefinedonto every single?-marked optional property; however, this is incredibly tedious for an existing project.We'd like to provide some automated tooling to help alleviate this, which is why I've opened up #44419.
Surrounding Community Upgrade Woes
There are really 3 places that are outside most users' control that need to be upgraded to work correctly with
strictOptionalProperties:lib.d.ts@typespackages)The last one is the hardest to solve; however, the first two are way more automatable, and we can have the core team help with it, but it's definitely time taken away from other work, and that's a delicate tradeoff.
I haven't created an issue to manage this one, but I think it might be worth distributing segments of
lib.d.tsand some number of top packages to add| undefinedto the definitions and see if that helps. Ideally, automation from #44419 could help. We'd also have to update thelib.dom.d.tsgenerator to emit| undefinedon most optional properties.I'd like to get @RyanCavanaugh's thoughts on this one.
Other Feedback
I'm curious to hear feedback from users on this one - is it a useful option? Do you feel good about it and its purpose? Did it catch any interesting bugs? Let us know!
The text was updated successfully, but these errors were encountered: