Repository: TypeScript
Issue: TypeScript refactorings should not generate explicit generic type arguments for types that the source interface has omitted due to the existence of defaults
Labels: Suggestion,Help Wanted,Domain: Refactorings,Experience Enhancement

# Suggestion

<!--
  Please fill in each section completely. Thank you!
-->

## 🔍 Search Terms

<!--
  💡 Did you know? TypeScript has over 2,000 open suggestions!
  🔎 Please search thoroughly before logging new feature requests as most common ideas already have a proposal in progress.
  The "Common Feature Requests" section of the FAQ lists many popular requests: https://github.com/Microsoft/TypeScript/wiki/FAQ#common-feature-requests

  Replace the text below:
-->

List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.

- refactor
- generic
- parameter
- type
- arguments
- default
- expand

## ✅ Viability Checklist

<!--
   Suggestions that don't meet all these criteria are very, very unlikely to be accepted.
   We always recommend reviewing the TypeScript design goals before investing time writing
   a proposal for ideas outside the scope of the project.
-->
My suggestion meets these guidelines:

* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
* [x] This wouldn't change the runtime behavior of existing JavaScript code
* [x] This could be implemented without emitting different JS based on the types of the expressions
* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).


## ⭐ Suggestion

<!-- A summary of what you'd like to see added or changed -->

I use generic default arguments all the time, and much of my system's core set of interfaces includes the use of one or more generic parameters, most of which have defaults because there are many contexts in which I don't care about the type arguments and so I *want* my defaults to be used.

The refactorings offered by TypeScript for generating method stubs and so on always include _all_ generic defaults preloaded into the stubs, even though the method definition on the interface itself does not specify any type arguments.

In short, I am forever having to correct the code generated by TypeScript to remove all of the unwanted redundant type arguments it has included. If I wanted to be forced to specify the arguments every time, I wouldn't have provided defaults. TypeScript should acknowledge my omission of type arguments by following suit when it generates code that refers to types I've defined elsewhere.

## 📃 Motivating Example

<!--
  If you were announcing this feature in a blog post, what's a short explanation that shows
  a developer why this feature improves the language?
-->

Consider the following two interfaces, the second of which includes an unconstrained reference to the first:

```ts
interface Foo<T = any> {
  readonly data: T;
}

interface Bar {
  method (foo: Foo): void;
}
```

I now want to quickly scaffold a class that implements Bar, so I type the following into VSCode:

```ts
class Foo implements Bar {}
```

I now select the refactoring to "Implement interface 'Bar'":

![image](https://user-images.githubusercontent.com/298883/236341373-408c300b-297e-414e-bb2b-d2ce9208215d.png)

This now generates the following method stub:

```ts
class Foo implements Bar {
  method (foo: Foo<any>): void { // <any> is redundant - It should not have been included here
    throw new Error('Method not implemented.');
  }
}
```

If my interface doesn't provide explicit type arguments, then neither should the refactoring.

## 💻 Use Cases

<!--
  What do you want to use this for?
  What shortcomings exist with current approaches?
  What workarounds are you using in the meantime?
-->

This feature request is a general productivity issue. Especially when I am rapidly iterating on a codebase and making heavy use of generic types with more complex interfaces than what I described above, I've sometimes even found myself copying and pasting other code from my codebase rather than using the refactoring, just because I can't be bothered going through and deleting all the unwanted type arguments TypeScript has generated.