mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 02:15:12 -06:00
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
This commit is contained in:
parent
a910c8df13
commit
8513f78058
@ -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);
|
||||
}
|
||||
|
||||
64
tests/cases/fourslash/codeFixAddMissingMember20.ts
Normal file
64
tests/cases/fourslash/codeFixAddMissingMember20.ts
Normal file
@ -0,0 +1,64 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////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;
|
||||
}
|
||||
}`
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user