Fix implement-interface codefix for invalid interface types#63466
Open
danyalahmed1995 wants to merge 2 commits intomicrosoft:mainfrom
Open
Fix implement-interface codefix for invalid interface types#63466danyalahmed1995 wants to merge 2 commits intomicrosoft:mainfrom
danyalahmed1995 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the “Implement interface” codefix to avoid offering or applying the fix when the implemented interface reference (e.g. invalid type arguments) or required member types are already semantically invalid (e.g. unresolved type symbols), aligning behavior with the intent documented by existing fourslash tests.
Changes:
- Add semantic-diagnostics gating in
fixClassIncorrectlyImplementsInterfaceto suppress the fix when the implemented type or its required members have blocking semantic errors. - Update existing fourslash tests to assert that no codefix is offered for invalid type argument instantiations and unresolved member type symbols.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts |
Adds semantic error checks to prevent offering the implement-interface fix when interface/member types are already invalid. |
tests/cases/fourslash/codeFixClassImplementInterfaceUndeclaredSymbol.ts |
Updates expectations to assert no codefix is offered when required member types reference an undeclared symbol. |
tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamInstantiateError.ts |
Updates expectations to assert no codefix is offered when the implemented interface instantiation is semantically invalid. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #63465
This updates the implement-interface codefix so it is not offered when the implemented interface reference or required member types are already semantically invalid.
The existing fourslash coverage already documented these cases as undesirable, but still expected the fix to be available. This PR updates those tests to assert that no codefix is offered for:
Validation:
npx.cmd hereby runtests --tests=tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamInstantiateError.ts --light=falsenpx.cmd hereby runtests --tests=tests/cases/fourslash/codeFixClassImplementInterfaceUndeclaredSymbol.ts --light=falsenpx.cmd hereby runtests --tests=tests/cases/fourslash/codeFixClassImplementInterfaceTypeParamInstantiateNumber.ts --light=falsegit diff --check