-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fixUnusedIdentifier: Don't remove parameter in override or non-last parameter in callback #24306
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
Conversation
…arameter in callback
4aadf21
to
d6f95e2
Compare
// Can't remove a non-last parameter in a callback. (Can if future parameters are also unused.) | ||
const index = parent.parameters.indexOf(p); | ||
Debug.assert(index !== -1); | ||
return parent.parameters.slice(index).every(p => p.name.kind === SyntaxKind.Identifier && !p.symbol.isReferenced) || !checker.getContextualType(parent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even if you did not have a contextual type, the function may be called or assigned to something else that passes or expects different parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, though it would mean we could never remove any parameters. Maybe we should play it safe in code-fix-all but still provide the option to delete as a single fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is always safe to remove from the end, contextual type or not.
We should think about updating call sites to remove the unused arguments as well.. but that is a different change..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So never remove a non-last parameter? A method in a class may also be expected to conform to some interface that wasn't declared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a method with fewer required arguments is assignable to one with more. so that should work. but yes, it could result in errors.. really any change to the signature can result in errors.. so we can either be conservative and say we only do it if we know all references, and know it was never aliased, or we can be more open and say, as long as the error will be caught by type check, we should be fine..
9e5e161
to
9bf1690
Compare
Fixes #24303