From 8513f78058b17e430e04844e4de8d4b62009eaa1 Mon Sep 17 00:00:00 2001 From: Jean Pierre Date: Tue, 20 Apr 2021 12:00:34 -0500 Subject: [PATCH] Fix getCodeFixesAtPosition for ts(2339) thows error False expression: Token end is child end (#43645) * Fix getCodeFixesAtPosition for ts(2339) thows error False expression: Token end is child end Fixes #43191 * Add test --- src/services/codefixes/fixAddMissingMember.ts | 4 +- .../fourslash/codeFixAddMissingMember20.ts | 64 +++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/codeFixAddMissingMember20.ts diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 0b240648a7b..92a6f7647a1 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -276,11 +276,11 @@ namespace ts.codefix { const binaryExpression = token.parent.parent as BinaryExpression; const otherExpression = token.parent === binaryExpression.left ? binaryExpression.right : binaryExpression.left; const widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(otherExpression))); - typeNode = checker.typeToTypeNode(widenedType, classDeclaration, /*flags*/ undefined); + typeNode = checker.typeToTypeNode(widenedType, classDeclaration, NodeBuilderFlags.NoTruncation); } else { const contextualType = checker.getContextualType(token.parent as Expression); - typeNode = contextualType ? checker.typeToTypeNode(contextualType, /*enclosingDeclaration*/ undefined, /*flags*/ undefined) : undefined; + typeNode = contextualType ? checker.typeToTypeNode(contextualType, /*enclosingDeclaration*/ undefined, NodeBuilderFlags.NoTruncation) : undefined; } return typeNode || factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); } diff --git a/tests/cases/fourslash/codeFixAddMissingMember20.ts b/tests/cases/fourslash/codeFixAddMissingMember20.ts new file mode 100644 index 00000000000..b45d5964016 --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingMember20.ts @@ -0,0 +1,64 @@ +/// + +////class C { +//// method() { +//// const { +//// many01, +//// many02, +//// many03, +//// many04, +//// many05, +//// many06, +//// many07, +//// many08, +//// many09, +//// many10, +//// many11, +//// many12, +//// many13, +//// many14, +//// many15, +//// many16, +//// many17, +//// many18, +//// many19, +//// many20, +//// many21, +//// many22 +//// } = this.foo; +//// } +////} + +verify.codeFix({ + description: "Declare property 'foo'", + index: 0, + newFileContent: `class C { + foo: { many01: any; many02: any; many03: any; many04: any; many05: any; many06: any; many07: any; many08: any; many09: any; many10: any; many11: any; many12: any; many13: any; many14: any; many15: any; many16: any; many17: any; many18: any; many19: any; many20: any; many21: any; many22: any; }; + method() { + const { + many01, + many02, + many03, + many04, + many05, + many06, + many07, + many08, + many09, + many10, + many11, + many12, + many13, + many14, + many15, + many16, + many17, + many18, + many19, + many20, + many21, + many22 + } = this.foo; + } +}` +});