microsoft/TypeScript · error · Error
There were no errors and declFiles generated did not match n
Error message
There were no errors and declFiles generated did not match number of js files generated
What it means
Thrown by prepareDeclarationCompilationContext when declaration:true, emitDeclarationOnly is not set, compilation produced no errors, but the number of declaration files (result.dts.size) does not equal the number of JS files (getNumberOfJsFiles excluding JSON). The harness expects a one-to-one correspondence between .d.ts and .js outputs for declaration-emit tests.
Source
Thrown at src/harness/harnessIO.ts:407
}
export function prepareDeclarationCompilationContext(
inputFiles: readonly TestFile[],
otherFiles: readonly TestFile[],
result: compiler.CompilationResult,
harnessSettings: TestCaseParser.CompilerSettings & HarnessOptions,
options: ts.CompilerOptions,
// Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
currentDirectory: string | undefined,
): DeclarationCompilationContext | undefined {
if (options.declaration && result.diagnostics.length === 0) {
if (options.emitDeclarationOnly) {
if (result.js.size > 0 || (result.dts.size === 0 && !options.noEmit)) {
throw new Error("Only declaration files should be generated when emitDeclarationOnly:true");
}
}
else if (result.dts.size !== result.getNumberOfJsFiles(/*includeJson*/ false)) {
throw new Error("There were no errors and declFiles generated did not match number of js files generated");
}
}
const declInputFiles: TestFile[] = [];
const declOtherFiles: TestFile[] = [];
// if the .d.ts is non-empty, confirm it compiles correctly as well
if (options.declaration && result.diagnostics.length === 0 && result.dts.size > 0) {
ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles));
ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles));
return { declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory: currentDirectory || harnessSettings.currentDirectory };
}
function addDtsFile(file: TestFile, dtsFiles: TestFile[]) {
if (vpath.isDeclaration(file.unitName) || vpath.isJson(file.unitName)) {
dtsFiles.push(file);
}
else if (vpath.isTypeScript(file.unitName) || (vpath.isJavaScript(file.unitName) && ts.getAllowJSCompilerOption(options))) {
View on GitHub (pinned to b465fdbfe1)
Solutions
- List result.dts and result.js contents to identify which files are missing a counterpart.
- If a compiler change intentionally altered the pairing, update the test expectations accordingly.
- If a file legitimately emits only JS (e.g. a .js input), exclude it from the declaration test inputs or adjust the harness count.
Defensive patterns
Strategy: validation
Validate before calling
// Verify the 1:1 dts/js correspondence before declaration baselining
if (options.declaration && !options.emitDeclarationOnly && result.diagnostics.length === 0) {
if (result.dts.size !== result.getNumberOfJsFiles(false)) {
throw new Error(`dts=${result.dts.size} js=${result.getNumberOfJsFiles(false)} mismatch`);
}
} Prevention
- Ensure every JS-emitting input in a declaration test is also a declaration candidate.
- After compiler changes that affect emit granularity, re-validate declaration tests.
When it happens
Trigger: A declaration-emit test compiles cleanly but produces a different count of .d.ts files than .js files — e.g. some files emit JS but no declaration, or vice versa. result.dts.size !== result.getNumberOfJsFiles(false).
Common situations: A compiler change alters declaration emit granularity (e.g. .d.ts merging or splitting), a test includes files that emit JS but are not declaration candidates, or a transform drops declarations for some files. Often signals a real compiler behaviour change rather than a config typo.
Related errors
- Only declaration files should be generated when emitDeclarat
- Number of sourcemap files should be same as js files.
- No sourcemap files should be generated if inlineSourceMaps w
- Cannot have undefined value for compiler option '${name}'.
- Unknown value '${value}' for compiler option '${name}'.
AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12).
Data as JSON: /api/errors/8b277b6c7b4299db.
Report an issue: GitHub.