Support deleting all unused type parameters in a list, and deleting @template tag#25748
Support deleting all unused type parameters in a list, and deleting @template tag#257482 commits merged intomasterfrom
Conversation
5577315 to
966aa80
Compare
|
Latest commit fixes #25594 |
|
|
||
| const name = idText(typeParameter.name); | ||
| const { parent } = typeParameter; | ||
| if (parent.kind !== SyntaxKind.InferType && parent.typeParameters!.every(isTypeParameterUnused)) { |
There was a problem hiding this comment.
You dont have to iterate on all parameters here, why not just iterate over the type parameters in the current loop and report error in the end of the loop instead?
There was a problem hiding this comment.
We need to know whether to report an error at each type parameter individually, or once for the whole list.
So when looking at a type parameter, we need to know whether all future type parameters are also unused. That needs at least two loops -- one to check isTypeParameterUnused for everything, and one to report errors individually if necessary. (We could cache the result of isTypeParameterUnused, but that's a simple function so probably not important to do.)
It's possible that we could calculate parent.typeParameters!.every(isTypeParameterUnused) eagerly instead of potentially once per loop, but the common case is that every type parameter is used. So in the common case, we only calculate isTypeParameterUnused once per type parameter, which is as efficient as it gets.
Previously code-fix-all at
function f<T, U>() {}would producefunction f<>() {}. And at/** @template T,U */ function f() {}it would crash.Incidentally fixes #24130.