Skip to content

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

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

Closed
Jutanium opened this issue Jun 27, 2022 · 2 comments · Fixed by #49727
Closed

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

Jutanium opened this issue Jun 27, 2022 · 2 comments · Fixed by #49727
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Help Wanted You can do this
Milestone

Comments

@Jutanium
Copy link

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.

⏯ 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 A bug in TypeScript Help Wanted You can do this Domain: Refactorings e.g. extract to constant or function, rename symbol labels Jun 27, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jun 27, 2022
@fatcerberus
Copy link

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

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

🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants