{"record":{"id":"098ae781efab8651","repo":"denoland/deno","slug":"type-checking-failed-098ae7","errorCode":null,"errorMessage":"Type checking failed:\n{}","messagePattern":"Type checking failed:\n(.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"cli/tools/transpile.rs","lineNumber":298,"sourceCode":"         '{}' uses scope '{}' but '{}' uses scope '{}'.\\n\\\n         Separate these files into different invocations.\",\n        first_specifier,\n        first_key,\n        specifier,\n        key,\n      );\n    }\n  }\n\n  let type_checker = factory.type_checker().await?;\n  let result = type_checker.emit_declarations(\n    Arc::new(graph),\n    root_names,\n    cli_options.ts_type_lib_window(),\n  )?;\n\n  if result.diagnostics.has_diagnostic() {\n    anyhow::bail!(\"Type checking failed:\\n{}\", result.diagnostics);\n  }\n\n  // Determine the output directory for .d.ts files.\n  // With -o, place .d.ts next to the output file.\n  // With --outdir, use the outdir.\n  // Otherwise, place next to the source file (handled by TSC path).\n  let output_base_dir = if let Some(output) = &transpile_flags.output {\n    let output_path = cwd.join(output);\n    output_path.parent().map(|p| p.to_path_buf())\n  } else {\n    None\n  };\n\n  // Write emitted .d.ts files\n  for (file_name, content) in &result.emitted_files {\n    // The file names from TSC are specifier-based, convert to output paths\n    let output_path = resolve_dts_output_path(\n      file_name,","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/cli/tools/transpile.rs#L280-L316","documentation":"Generating declarations requires type-checking. `type_checker.emit_declarations` returns diagnostics, and if any diagnostic is present the tool bails with the full formatted diagnostic list embedded after the 'Type checking failed:' header.","triggerScenarios":"Any TypeScript type error in the input files (or their imports) while `--declaration` is active.","commonSituations":"Enabling --declaration on a codebase `deno check` never ran against; strictness differences between a file's scope and the default config; type errors surfaced from dependency .d.ts files.","solutions":["Read the diagnostics after the header — each is `file(line,col): error TS####: message`; fix them top-down since the first error often cascades","Iterate with `deno check <same inputs>` — it surfaces the same diagnostics without re-running emit","If declarations are not needed, drop --declaration; plain transpile skips type-checking entirely"],"exampleFix":"// before (mod.ts)\nexport function add(a: number, b: string) { return a + b; }\n// after\nexport function add(a: number, b: number): number { return a + b; }","handlingStrategy":"try-catch","validationCode":"# run the same type-check first; only transpile on a clean pass\ndeno check src/*.ts && deno transpile --declaration src/*.ts --outdir dist","typeGuard":null,"tryCatchPattern":"# bash wrapper: surface diagnostics, fail loudly\nif ! output=$(deno transpile --declaration src/mod.ts --outdir dist 2>&1); then\n  echo \"$output\" | sed -n '/Type checking failed:/,$p'\n  exit 1\nfi","preventionTips":["Keep the codebase `deno check`-clean so enabling --declaration is free","Fix diagnostics top-down — the first error often cascades into the rest","Run deno check in CI before any declaration-emitting step"],"tags":["cli","transpile","typescript","type-check","diagnostics"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}