Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
6 tasks done
Elie-A-98 opened this issue Feb 25, 2025 · 0 comments
Open
6 tasks done

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

Elie-A-98 opened this issue Feb 25, 2025 · 0 comments
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

Comments

@Elie-A-98
Copy link

Elie-A-98 commented Feb 25, 2025

🔍 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?
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants