{"record":{"id":"098ae781efab8651","repo":"denoland/deno","slug":"type-checking-failed","errorCode":null,"errorMessage":"Type checking failed:\n{}","messagePattern":"Type checking failed:\n(.+?)","errorType":"exception","errorClass":"AnyError","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/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/tools/transpile.rs#L280-L316","documentation":"Declaration emit in Deno runs a full TSC type-check of the module graph first (`type_checker.emit_declarations`). If TSC returns any diagnostics, Deno bails with 'Type checking failed' followed by the formatted diagnostic list. This is the standard TypeScript error surface (TS2xxx codes) relayed during `deno cache`/declaration generation, not a Deno-internal failure.","triggerScenarios":"Any TypeScript type error in the program being checked: bad imports types, wrong argument types, missing exports, `strict` violations, or errors in dependencies pulled into the graph. It fires as soon as `result.diagnostics.has_diagnostic()` is true after `emit_declarations` at cli/tools/transpile.rs:298.","commonSituations":"Running `deno cache` (with type-checking enabled) or emitting declarations on code that has never been `deno check`ed; tightening `strict`/`noUncheckedIndexedAccess` in deno.json compilerOptions and re-caching; upgrading Deno/TS versions that surface new diagnostics in previously-passing code.","solutions":["Read the diagnostics printed after the header and fix the listed type errors in the named files.","Run `deno check <entrypoint>` to reproduce and iterate on the same diagnostics quickly.","If the errors come from newly enabled compilerOptions, relax them or fix the code they now flag.","If you only need transpilation (not declarations), run without type-checking (e.g. `--no-check`) — but note declaration generation always requires a clean type-check."],"exampleFix":"// before: type error that triggers the diagnostic\nexport const count: number = parseInt(\"1\"); // ok, but:\nexport const bad: number = \"1\"; // TS2322\n\n// after\nexport const bad: number = parseInt(\"1\");","handlingStrategy":"validation","validationCode":"# fail fast on type errors before generating anything\ndeno check main.ts || { echo \"fix type errors first\"; exit 1; }\ndeno cache main.ts","typeGuard":null,"tryCatchPattern":"output=$(deno cache main.ts 2>&1) || { echo \"$output\" | grep '^TS[0-9]' ; exit 1; }","preventionTips":["Run `deno check` in CI before any declaration-emitting command.","Enable strict options gradually; re-cache after each change to keep diagnostics small.","Treat the diagnostics after 'Type checking failed:' as authoritative TS errors, not Deno internals."],"tags":["typescript","type-check","tsc","diagnostics","declarations"],"backgroundTag":"typescript-type-errors","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}