Fixed an issue with errors not being correctly reported after completion requests in nested calls (#54658)

This commit is contained in:
Mateusz Burzyński 2023-06-20 21:04:08 +02:00 committed by GitHub
parent b1c2e8caad
commit abf0ef8eef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 6 deletions

View File

@ -1828,14 +1828,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
};
function runWithoutResolvedSignatureCaching<T>(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;
}

View File

@ -0,0 +1,32 @@
///<reference path="fourslash.ts"/>
// @strict: true
////
//// type GreetingEvent =
//// | { type: "MORNING" }
//// | { type: "LUNCH_TIME" }
//// | { type: "ALOHA" };
////
//// interface RaiseActionObject<TEvent extends { type: string }> {
//// type: "raise";
//// event: TEvent;
//// }
////
//// declare function raise<TEvent extends { type: string }>(
//// ev: TEvent
//// ): RaiseActionObject<TEvent>;
////
//// declare function createMachine<TEvent extends { type: string }>(config: {
//// actions: RaiseActionObject<TEvent>;
//// }): void;
////
//// createMachine<GreetingEvent>({
//// [|/*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<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"'.`,
}]);