microsoft/TypeScript · error · Error
Three-slash line in the middle of four-slash region at line
Error message
Three-slash line in the middle of four-slash region at line
What it means
Thrown by parseTestData when a three-slash line (starting with /// but not ////) appears after fourslash content lines (starting with ////) have begun accumulating currentFileContent. The parser treats //// as file content and /// as an ambiguous instruction that must not be interleaved with four-slash blocks.
Source
Thrown at src/harness/fourslashImpl.ts:4788
currentFileContent = undefined;
currentFileOptions = {};
currentFileName = fileName;
currentFileSymlinks = undefined;
}
for (let line of lines) {
i++;
if (line.length > 0 && line.charAt(line.length - 1) === "\r") {
line = line.substr(0, line.length - 1);
}
if (line.substr(0, 4) === "////") {
const text = line.substr(4);
currentFileContent = currentFileContent === undefined ? text : currentFileContent + "\n" + text;
}
else if (line.substr(0, 3) === "///" && currentFileContent !== undefined) {
throw new Error("Three-slash line in the middle of four-slash region at line " + i);
}
else if (line.substr(0, 2) === "//") {
const possiblySymlinks = Harness.TestCaseParser.parseSymlinkFromTest(line, symlinks);
if (possiblySymlinks) {
symlinks = possiblySymlinks;
}
else {
// Comment line, check for global/file @options and record them
const match = optionRegex.exec(line.substr(2));
if (match) {
const key = match[1].toLowerCase();
const value = match[2];
if (!ts.contains(fileMetadataNames, key)) {
// Check if the match is already existed in the global options
if (globalOptions[key] !== undefined) {
throw new Error(`Global option '${key}' already exists`);
}
globalOptions[key] = value;
View on GitHub (pinned to b465fdbfe1)
Solutions
- Inspect the line number reported in the message and convert the /// line to //// if it is meant to be file content.
- If the /// line is a real triple-slash directive, move it before the first //// block (outside the four-slash region).
- Remove the stray line entirely if it is not needed.
Example fix
// before ////const x = 1; /// <reference path="a.d.ts" /> ////const y = 2; // after — reference moved above the four-slash region /// <reference path="a.d.ts" /> ////const x = 1; ////const y = 2;
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check that no /// lines appear after the first //// line in a test file
const lines = content.split("\n");
let sawFourSlash = false;
for (const line of lines) {
if (line.startsWith("////")) sawFourSlash = true;
else if (sawFourSlash && line.startsWith("///") && !line.startsWith("////")) {
throw new Error(`Stray /// after //// region: ${line}`);
}
} Prevention
- Place all triple-slash directives above the first //// content block.
- When editing fourslash files, count slashes carefully — /// vs //// have distinct meanings.
When it happens
Trigger: A fourslash test file mixes //// content lines with a /// line in the same region — e.g. a stray triple-slash reference comment placed between four-slash file content lines.
Common situations: Test author adds a ///<reference> directive inside a four-slash block by mistake, or a copy-paste introduces a /// line where //// was intended. Also happens when trimming one slash from a //// comment accidentally.
Related errors
- Global option '${key}' already exists
- ${fileName}(${line},${col}): ${message}
- verifyCurrentLineContent\n
- verifyFileContent in file '${fileName}' failed:\n${showTextD
- verifyTextAtCaretIs\n
AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12).
Data as JSON: /api/errors/c239521baf8fcf5a.
Report an issue: GitHub.