Skip to content

Commit abf0ef8

Browse files
authored
Fixed an issue with errors not being correctly reported after completion requests in nested calls (#54658)
1 parent b1c2e8c commit abf0ef8

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,14 +1828,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
18281828
};
18291829

18301830
function runWithoutResolvedSignatureCaching<T>(node: Node | undefined, fn: () => T): T {
1831-
const containingCall = findAncestor(node, isCallLikeExpression);
1832-
const containingCallResolvedSignature = containingCall && getNodeLinks(containingCall).resolvedSignature;
1833-
if (containingCall) {
1834-
getNodeLinks(containingCall).resolvedSignature = undefined;
1831+
const cachedSignatures = [];
1832+
while (node) {
1833+
if (isCallLikeExpression(node)) {
1834+
const nodeLinks = getNodeLinks(node);
1835+
const resolvedSignature = nodeLinks.resolvedSignature;
1836+
cachedSignatures.push([nodeLinks, resolvedSignature] as const);
1837+
nodeLinks.resolvedSignature = undefined;
1838+
}
1839+
node = node.parent;
18351840
}
18361841
const result = fn();
1837-
if (containingCall) {
1838-
getNodeLinks(containingCall).resolvedSignature = containingCallResolvedSignature;
1842+
for (const [nodeLinks, resolvedSignature] of cachedSignatures) {
1843+
nodeLinks.resolvedSignature = resolvedSignature;
18391844
}
18401845
return result;
18411846
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
///<reference path="fourslash.ts"/>
2+
// @strict: true
3+
////
4+
//// type GreetingEvent =
5+
//// | { type: "MORNING" }
6+
//// | { type: "LUNCH_TIME" }
7+
//// | { type: "ALOHA" };
8+
////
9+
//// interface RaiseActionObject<TEvent extends { type: string }> {
10+
//// type: "raise";
11+
//// event: TEvent;
12+
//// }
13+
////
14+
//// declare function raise<TEvent extends { type: string }>(
15+
//// ev: TEvent
16+
//// ): RaiseActionObject<TEvent>;
17+
////
18+
//// declare function createMachine<TEvent extends { type: string }>(config: {
19+
//// actions: RaiseActionObject<TEvent>;
20+
//// }): void;
21+
////
22+
//// createMachine<GreetingEvent>({
23+
//// [|/*error*/actions|]: raise({ type: "ALOHA/*1*/" }),
24+
//// });
25+
26+
goTo.marker("1");
27+
edit.insert(`x`)
28+
verify.completions({ exact: ["MORNING", "LUNCH_TIME", "ALOHA"] });
29+
verify.getSemanticDiagnostics([{
30+
code: 2322,
31+
message: `Type 'RaiseActionObject<{ type: "ALOHAx"; }>' is not assignable to type 'RaiseActionObject<GreetingEvent>'.\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"'.`,
32+
}]);

0 commit comments

Comments
 (0)