Add a flag to error when an uninitialized function is called #61267
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
🔍 Search Terms
uninitialized function - uninitialized - uninitialized function call
✅ Viability Checklist
⭐ Suggestion
This is a request to add a new configuration flag that makes typescript error when an uninitialized function is called within the same scope
This is a comment made by @RyanCavanaugh on a similar topic (using an uninitialized variable) for why an error is not thrown by typescript in the case of using an uninitialized variable (not calling a function)
There are more comments on this topic
But the same argument of why function parameters assignment is contra-variant applies to why throw an error when an uninitialized function is called. Typescript doesn't know if it will surely error but it prevents it anyway
📃 Motivating Example
The below is a case of a runtime error thrown by calling an uninitialized variable which typescript didn't prevent
https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABAMXBAjIgFKSAubASgF4A+ANzhgBNCBvAKEWcVwi0MQHovEoALGAGc+-AE5wA7iICGiMeFgBbAKaIVYiWKYsxKqCDFI65GQBsQKggCYAvg3sM2sBIgDm+gHIrJqSEURGFnl9QyQORDJECAQhODMVADozODcsAANvXzR0wgcGBh4YsCEoQNMLFVtIlDR0LDAfPwhOHnUADwAHFWgVakQAIxV+GXJ4MQIBYVEJaUQ5KABPbqEIMRhOso0tRE69chUwWDA3eUUYVXVNODEhBmb6jjI6REbsyAjbVt5wFS6eqB9QbDUbjSaCETUOAqIRgADkZQEs3mfGWMLWGy21zEiEkggg-EQCRk1BEUDgKIURwuam2NwKxVKryaaBqHigWWaHCAA
💻 Use Cases
The text was updated successfully, but these errors were encountered: