Give ts error when using optional chaining or nullish coalescing on nonnullable object #46268
Open
3 of 5 tasks
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Suggestion
It sometimes happens that a variable / prop was original nullable, but evolved to be non-nullable, but there are places using it with ? not removed.
🔍 Search Terms
optional chainning
,feature request
,nonnullable
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Gives ts error when optional chaining is used on a nonnullable object.
📃 Motivating Example
After few iteration,
a
becomes nonnullable:However, we are not aware of those usages. This can help to reduce the output JS file size by removing unnecessary code.
💻 Use Cases
We want use this to remove unnecessary code and hence reduce the size of emitted JS file.
The text was updated successfully, but these errors were encountered: