diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bdf2dff585a47..87317a73b1a76 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1828,14 +1828,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { }; function runWithoutResolvedSignatureCaching(node: Node | undefined, fn: () => T): T { - const containingCall = findAncestor(node, isCallLikeExpression); - const containingCallResolvedSignature = containingCall && getNodeLinks(containingCall).resolvedSignature; - if (containingCall) { - getNodeLinks(containingCall).resolvedSignature = undefined; + const cachedSignatures = []; + while (node) { + if (isCallLikeExpression(node)) { + const nodeLinks = getNodeLinks(node); + const resolvedSignature = nodeLinks.resolvedSignature; + cachedSignatures.push([nodeLinks, resolvedSignature] as const); + nodeLinks.resolvedSignature = undefined; + } + node = node.parent; } const result = fn(); - if (containingCall) { - getNodeLinks(containingCall).resolvedSignature = containingCallResolvedSignature; + for (const [nodeLinks, resolvedSignature] of cachedSignatures) { + nodeLinks.resolvedSignature = resolvedSignature; } return result; } diff --git a/tests/cases/fourslash/typeErrorAfterStringCompletionsInNestedCall.ts b/tests/cases/fourslash/typeErrorAfterStringCompletionsInNestedCall.ts new file mode 100644 index 0000000000000..6a9909c4a20e3 --- /dev/null +++ b/tests/cases/fourslash/typeErrorAfterStringCompletionsInNestedCall.ts @@ -0,0 +1,32 @@ +/// +// @strict: true +//// +//// type GreetingEvent = +//// | { type: "MORNING" } +//// | { type: "LUNCH_TIME" } +//// | { type: "ALOHA" }; +//// +//// interface RaiseActionObject { +//// type: "raise"; +//// event: TEvent; +//// } +//// +//// declare function raise( +//// ev: TEvent +//// ): RaiseActionObject; +//// +//// declare function createMachine(config: { +//// actions: RaiseActionObject; +//// }): void; +//// +//// createMachine({ +//// [|/*error*/actions|]: raise({ type: "ALOHA/*1*/" }), +//// }); + +goTo.marker("1"); +edit.insert(`x`) +verify.completions({ exact: ["MORNING", "LUNCH_TIME", "ALOHA"] }); +verify.getSemanticDiagnostics([{ + code: 2322, + message: `Type 'RaiseActionObject<{ type: "ALOHAx"; }>' is not assignable to type 'RaiseActionObject'.\n Type '{ type: "ALOHAx"; }' is not assignable to type 'GreetingEvent'.\n Type '{ type: "ALOHAx"; }' is not assignable to type '{ type: "ALOHA"; }'.\n Types of property 'type' are incompatible.\n Type '"ALOHAx"' is not assignable to type '"ALOHA"'.`, +}]);