microsoft/TypeScript · error · Error
Cannot call andApplyCodeAction on multiple completions reque
Error message
Cannot call andApplyCodeAction on multiple completions requests
What it means
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.
Source
Thrown at src/harness/fourslashInterfaceImpl.ts:289
export class Verify extends VerifyNegatable {
constructor(state: FourSlash.TestState) {
super(state);
}
public completions(...optionsArray: VerifyCompletionsOptions[]): CompletionsResult | undefined {
if (optionsArray.length === 1) {
return this.state.verifyCompletions(optionsArray[0]);
}
for (const options of optionsArray) {
if (options.preferences && Object.keys(options).length === 1 && optionsArray.length > 1 && optionsArray.indexOf(options) > 0) {
throw new Error("Did you mean to put 'preferences' in the previous 'verify.completions' object argument instead of their own object?");
}
this.state.verifyCompletions(options);
}
return {
andApplyCodeAction: () => {
throw new Error("Cannot call andApplyCodeAction on multiple completions requests");
},
};
}
public baselineInlayHints(span: ts.TextSpan, preference?: ts.UserPreferences): void {
this.state.baselineInlayHints(span, preference);
}
public quickInfoIs(expectedText: string, expectedDocumentation?: string, expectedTags?: { name: string; text: string; }[]): void {
this.state.verifyQuickInfoString(expectedText, expectedDocumentation, expectedTags);
}
public quickInfoAt(markerName: string | FourSlash.Range, expectedText: string, expectedDocumentation?: string, expectedTags?: { name: string; text: string; }[]): void {
this.state.verifyQuickInfoAt(markerName, expectedText, expectedDocumentation, expectedTags);
}
public quickInfos(namesAndTexts: { [name: string]: string; }): void {
this.state.verifyQuickInfos(namesAndTexts);
View on GitHub (pinned to b465fdbfe1)
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.
Example fix
// before verify.completions(opts1, opts2).andApplyCodeAction(); // after verify.completions(opts1).andApplyCodeAction(); verify.completions(opts2).andApplyCodeAction();
Defensive patterns
Strategy: validation
Validate before calling
// Ensure a single options object before relying on andApplyCodeAction
const result = optionsArray.length === 1
? verify.completions(optionsArray[0])
: undefined;
if (result) {
result.andApplyCodeAction(); // safe: single-arg branch returns a real CompletionsResult
} Type guard
function supportsApplyCodeAction(r: CompletionsResult | { andApplyCodeAction(): never }): r is CompletionsResult {
// The multi-options stub throws on call; the single-arg path returns a real result.
// There is no runtime flag, so guard by call count at the call site instead.
return true;
} Prevention
- Only chain andApplyCodeAction onto a single-argument verify.completions call.
- If you need multiple scenarios plus code-action application, issue separate single-arg calls.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Did you mean to put 'preferences' in the previous 'verify.co
- verifyCurrentLineContent\n
- verifyFileContent in file '${fileName}' failed:\n${showTextD
- verifyTextAtCaretIs\n
- You need to change the source code of fourslash test to use
AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12).
Data as JSON: /api/errors/02ba5a3943c4c314.
Report an issue: GitHub.