-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
π Search Terms
uninitialized function - uninitialized - uninitialized function call
β Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
β 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
π» Use Cases
- What do you want to use this for? Preventing runtime errors
- What shortcomings exist with current approaches? none
- What workarounds are you using in the meantime?
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript