Skip to content

Quick fix to correct qualified names to indexed access types - #17462

Merged
Daniel Rosenwasser (DanielRosenwasser) merged 5 commits into
masterfrom
codeFixForErrorForPropertyOfTypeAsType
Jul 27, 2017
Merged

Quick fix to correct qualified names to indexed access types#17462
Daniel Rosenwasser (DanielRosenwasser) merged 5 commits into
masterfrom
codeFixForErrorForPropertyOfTypeAsType

Conversation

@DanielRosenwasser

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) commented Jul 27, 2017

Copy link
Copy Markdown
Member

Fixes #17461

qnwithiat

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) changed the title Code fix for error for property of type as type Quick fix to correct qualified names to indexed access types Jul 27, 2017

@aozgaa Arthur Ozga (aozgaa) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure you want to make changes to get the fix working in the case mentioned below, but please add a test.

const token = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
const qualifiedName = getAncestor(token, SyntaxKind.QualifiedName) as QualifiedName;
Debug.assert(!!qualifiedName, "Expected position to be owned by a qualified name.");
if (!isIdentifier(qualifiedName.left)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example doesn't seem to trigger the right error, though we can apply the fix manually to fix the issue:

module M {
    export interface I {
         foo: string;
    }
}
let a: M.I.foo;

Please add a test.

@@ -1,3 +1,4 @@
/// <reference path="correctQualifiedNameToIndexedAccessType.ts" />
/// <reference path="fixClassIncorrectlyImplementsInterface.ts" />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is an analogous entry to this in src/harness/tsconfig.json. Not sure why it's there, or if we might want to remove it. Or alternatively, add a reference to correctQualifiedNameToIndexedAccessType.ts.

Wesley Wigham (@weswigham) do you know if building for tests will correctly trigger a rebuild when we make changes to correctQualifiedNameToIndexedAccessType.ts?

@DanielRosenwasser

Copy link
Copy Markdown
Member Author

Arthur Ozga (@aozgaa) no, I didn't generalize the check, but I can at a later point. I did add a negative fourslash test, and augmented the tests added in #17459.

…e already referenced in 'src/harness/codefixes/fixes.ts'.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants