Skip to content

Add a flag to error when an uninitialized function is calledΒ #61267

Open
@Elie-A-98

Description

@Elie-A-98

πŸ” 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

  1. What do you want to use this for? Preventing runtime errors
  2. What shortcomings exist with current approaches? none
  3. What workarounds are you using in the meantime?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions