{"record":{"id":"02ba5a3943c4c314","repo":"microsoft/TypeScript","slug":"cannot-call-andapplycodeaction-on-multiple-complet","errorCode":null,"errorMessage":"Cannot call andApplyCodeAction on multiple completions requests","messagePattern":"Cannot call andApplyCodeAction on multiple completions requests","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/harness/fourslashInterfaceImpl.ts","lineNumber":289,"sourceCode":"\r\nexport class Verify extends VerifyNegatable {\r\n    constructor(state: FourSlash.TestState) {\r\n        super(state);\r\n    }\r\n\r\n    public completions(...optionsArray: VerifyCompletionsOptions[]): CompletionsResult | undefined {\r\n        if (optionsArray.length === 1) {\r\n            return this.state.verifyCompletions(optionsArray[0]);\r\n        }\r\n        for (const options of optionsArray) {\r\n            if (options.preferences && Object.keys(options).length === 1 && optionsArray.length > 1 && optionsArray.indexOf(options) > 0) {\r\n                throw new Error(\"Did you mean to put 'preferences' in the previous 'verify.completions' object argument instead of their own object?\");\r\n            }\r\n            this.state.verifyCompletions(options);\r\n        }\r\n        return {\r\n            andApplyCodeAction: () => {\r\n                throw new Error(\"Cannot call andApplyCodeAction on multiple completions requests\");\r\n            },\r\n        };\r\n    }\r\n\r\n    public baselineInlayHints(span: ts.TextSpan, preference?: ts.UserPreferences): void {\r\n        this.state.baselineInlayHints(span, preference);\r\n    }\r\n\r\n    public quickInfoIs(expectedText: string, expectedDocumentation?: string, expectedTags?: { name: string; text: string; }[]): void {\r\n        this.state.verifyQuickInfoString(expectedText, expectedDocumentation, expectedTags);\r\n    }\r\n\r\n    public quickInfoAt(markerName: string | FourSlash.Range, expectedText: string, expectedDocumentation?: string, expectedTags?: { name: string; text: string; }[]): void {\r\n        this.state.verifyQuickInfoAt(markerName, expectedText, expectedDocumentation, expectedTags);\r\n    }\r\n\r\n    public quickInfos(namesAndTexts: { [name: string]: string; }): void {\r\n        this.state.verifyQuickInfos(namesAndTexts);\r","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/harness/fourslashInterfaceImpl.ts#L271-L307","documentation":"Thrown by the andApplyCodeAction callback returned from Verify.completions when completions was called with more than one option object. andApplyCodeAction only makes sense for a single completions request, so the multi-options path returns an object whose andApplyCodeAction throws to prevent ambiguous application.","triggerScenarios":"Calling verify.completions(opts1, opts2).andApplyCodeAction() — any chained application after a multi-argument completions call. The single-argument fast path returns a real CompletionsResult with a working andApplyCodeAction.","commonSituations":"Test author loops several completion scenarios and then tries to apply a code action on the aggregate result, not realising the multi-arg return value is a stub.","solutions":["Restructure to a single verify.completions(opts) call when you need andApplyCodeAction, so it hits the single-argument branch returning a real CompletionsResult.","If multiple scenarios are needed, apply the code action inside each individual verify.completions(opts) call rather than on the combined result."],"exampleFix":"// before\nverify.completions(opts1, opts2).andApplyCodeAction();\n// after\nverify.completions(opts1).andApplyCodeAction();\nverify.completions(opts2).andApplyCodeAction();","handlingStrategy":"validation","validationCode":"// Ensure a single options object before relying on andApplyCodeAction\nconst result = optionsArray.length === 1\n    ? verify.completions(optionsArray[0])\n    : undefined;\nif (result) {\n    result.andApplyCodeAction(); // safe: single-arg branch returns a real CompletionsResult\n}","typeGuard":"function supportsApplyCodeAction(r: CompletionsResult | { andApplyCodeAction(): never }): r is CompletionsResult {\n    // The multi-options stub throws on call; the single-arg path returns a real result.\n    // There is no runtime flag, so guard by call count at the call site instead.\n    return true;\n}","tryCatchPattern":null,"preventionTips":["Only chain andApplyCodeAction onto a single-argument verify.completions call.","If you need multiple scenarios plus code-action application, issue separate single-arg calls."],"tags":["fourslash","completions","api-misuse","code-action"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}