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 Missing Function Declaration: Does Not Correctly Declare Generic Function #49693

Open
Jutanium opened this issue Jun 27, 2022 · 2 comments · May be fixed by #49727
Open

Add Missing Function Declaration: Does Not Correctly Declare Generic Function #49693

Jutanium opened this issue Jun 27, 2022 · 2 comments · May be fixed by #49727
Labels
Bug Domain: Refactorings Help Wanted
Milestone

Comments

@Jutanium
Copy link

@Jutanium Jutanium commented Jun 27, 2022

Bug Report

The "Quick Feature" allows us to generate a missing a function, but doesn't correctly declare that function when its parameters include a type parameter.

See also unexpected behavior when type narrowing in this example.

🔎 Search Terms

  • add missing function declaration
  • generic type parameter

🕗 Version & Regression Information

I am unable to find a version of TypeScript where this was not a problem.

⏄1�7 Playground Link

Playground link with relevant code

💻 Code

function identity<T>(self: T) {
 
  // To reproduce the bug, Quick Fix > Add missing function declaration
  runEvilSideEffect(self)

  return self;
}

🙁 Actual behavior

TypeScript generated this function, which is an invalid function declaration:

function runEvilSideEffect(self: T) {
    throw new Error("Function not implemented.");
}

🙂 Expected behavior

function runEvilSideEffect<T> (self: T) {
    throw new Error("Function not implemented.");
}
@RyanCavanaugh RyanCavanaugh added Bug Help Wanted Domain: Refactorings labels Jun 27, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jun 27, 2022
@fatcerberus
Copy link

@fatcerberus fatcerberus commented Jun 27, 2022

No doubt the current behavior is bad, but the question is which "correct" behavior is more useful: making the generated function generic as suggested here, or to just use the constraint of T?

@RyanCavanaugh
Copy link
Member

@RyanCavanaugh RyanCavanaugh commented Jun 28, 2022

making the generated function generic as suggested here, or to just use the constraint of T?

🤷‍♂︄1�7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Domain: Refactorings Help Wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants