Skip to content

Commit

Permalink
fix: skip type query
Browse files Browse the repository at this point in the history
Ilya Golovin committed Nov 14, 2023

Unverified

No user is associated with the committer email.
1 parent d3b04d5 commit 42fd392
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion typescript/src/codeActions/custom/addDestructure.ts
Original file line number Diff line number Diff line change
@@ -43,7 +43,13 @@ const addDestructureToVariableWithSplittedPropertyAccessors = (
const highlightedNode = findChildContainingExactPosition(sourceFile, pos)

if (!highlightedNode) continue
if (ts.isElementAccessExpression(highlightedNode.parent) || ts.isCallExpression(highlightedNode.parent.parent)) return

if (
ts.isElementAccessExpression(highlightedNode.parent) ||
ts.isCallExpression(highlightedNode.parent.parent) ||
ts.isTypeQueryNode(highlightedNode.parent)
)
return

if (ts.isIdentifier(highlightedNode) && ts.isPropertyAccessExpression(highlightedNode.parent)) {
const accessorName = highlightedNode.parent.name.getText()
17 changes: 17 additions & 0 deletions typescript/test/codeActions/addDestruct.spec.ts
Original file line number Diff line number Diff line change
@@ -262,6 +262,23 @@ describe('Add destructure', () => {

const { codeAction } = fourslashLikeTester(initial, undefined, { dedent: true })

codeAction(0, {
refactorName: 'Add Destruct',
newContent: null,
})
})
test('Should skip typeof operator', () => {
const initial = /* ts */ `
const /*t*/obj/*t*/ = {
test: 1,
}
obj.test
type foo = typeof obj;
`

const { codeAction } = fourslashLikeTester(initial, undefined, { dedent: true })

codeAction(0, {
refactorName: 'Add Destruct',
newContent: null,

0 comments on commit 42fd392

Please sign in to comment.