{"record":{"id":"8b277b6c7b4299db","repo":"microsoft/TypeScript","slug":"there-were-no-errors-and-declfiles-generated-did-n","errorCode":null,"errorMessage":"There were no errors and declFiles generated did not match number of js files generated","messagePattern":"There were no errors and declFiles generated did not match number of js files generated","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/harness/harnessIO.ts","lineNumber":407,"sourceCode":"    }\r\n\r\n    export function prepareDeclarationCompilationContext(\r\n        inputFiles: readonly TestFile[],\r\n        otherFiles: readonly TestFile[],\r\n        result: compiler.CompilationResult,\r\n        harnessSettings: TestCaseParser.CompilerSettings & HarnessOptions,\r\n        options: ts.CompilerOptions,\r\n        // Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file\r\n        currentDirectory: string | undefined,\r\n    ): DeclarationCompilationContext | undefined {\r\n        if (options.declaration && result.diagnostics.length === 0) {\r\n            if (options.emitDeclarationOnly) {\r\n                if (result.js.size > 0 || (result.dts.size === 0 && !options.noEmit)) {\r\n                    throw new Error(\"Only declaration files should be generated when emitDeclarationOnly:true\");\r\n                }\r\n            }\r\n            else if (result.dts.size !== result.getNumberOfJsFiles(/*includeJson*/ false)) {\r\n                throw new Error(\"There were no errors and declFiles generated did not match number of js files generated\");\r\n            }\r\n        }\r\n\r\n        const declInputFiles: TestFile[] = [];\r\n        const declOtherFiles: TestFile[] = [];\r\n\r\n        // if the .d.ts is non-empty, confirm it compiles correctly as well\r\n        if (options.declaration && result.diagnostics.length === 0 && result.dts.size > 0) {\r\n            ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles));\r\n            ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles));\r\n            return { declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory: currentDirectory || harnessSettings.currentDirectory };\r\n        }\r\n\r\n        function addDtsFile(file: TestFile, dtsFiles: TestFile[]) {\r\n            if (vpath.isDeclaration(file.unitName) || vpath.isJson(file.unitName)) {\r\n                dtsFiles.push(file);\r\n            }\r\n            else if (vpath.isTypeScript(file.unitName) || (vpath.isJavaScript(file.unitName) && ts.getAllowJSCompilerOption(options))) {\r","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/harness/harnessIO.ts#L389-L425","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the 1:1 dts/js correspondence before declaration baselining\nif (options.declaration && !options.emitDeclarationOnly && result.diagnostics.length === 0) {\n    if (result.dts.size !== result.getNumberOfJsFiles(false)) {\n        throw new Error(`dts=${result.dts.size} js=${result.getNumberOfJsFiles(false)} mismatch`);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["harness","compiler-output","declaration","emit","file-count-mismatch"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}