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

Missing properties quickfix does not handle generic parameters #47746

Closed
hpx7 opened this issue Feb 5, 2022 · 2 comments · Fixed by #47790
Closed

Missing properties quickfix does not handle generic parameters #47746

hpx7 opened this issue Feb 5, 2022 · 2 comments · Fixed by #47790
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

@hpx7
Copy link

hpx7 commented Feb 5, 2022

Bug Report

🔎 Search Terms

quickfix missing properties generic parameter

🕗 Version & Regression Information

The quickfix was added in #44576 (cc @a-tarasyuk) but it doesn't appear to handle generic parameters.

💻 Code

interface Foo<T> {
  foo(): T;
}
const x: Foo<string> = {};

🙁 Actual behavior

The following is generated by the quickfix:

interface Foo<T> {
  foo(): T;
}
const x: Foo<string> = {
  foo: function (): T { // <-- this is wrong
    throw new Error("Function not implemented.");
  }
};

🙂 Expected behavior

I would expect to see string instead of T:

interface Foo<T> {
  foo(): T;
}
const x: Foo<string> = {
  foo: function (): string {
    throw new Error("Function not implemented.");
  }
};
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Help Wanted You can do this labels Feb 7, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 7, 2022
@komyg
Copy link
Contributor

komyg commented Feb 7, 2022

Hey @RyanCavanaugh, I would like to help on this bug. Could you assign this issue to me?

@komyg
Copy link
Contributor

komyg commented Feb 7, 2022

Hey @RyanCavanaugh, it seems that this problem is already fixed in the nightly version of Typescript.

I've run a test in the playground and got the correct result: https://www.typescriptlang.org/play?ts=4.6.0-dev.20220116#code/JYOwLgpgTgZghgYwgAgGIHt0B4AqA+ZAbwFgAoZZGTACgEoAuZHAbjIF8yF0QBnMZAB6MM2PlFABzAgF4iZKukYwAriARhg3OozGS5pMAAso6AO7IQEcwFEoJqNQBEqVes0gL6fsAC2ABwAbCB8IcAgAEwA6R1pWUg545iA

image

I've opened a PR anyway, with an extra unit test for this case.

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