{"record":{"id":"620045b69a0e1bbb","repo":"denoland/deno","slug":"type-checking-failed-when-generating-declarations","errorCode":null,"errorMessage":"Type checking failed when generating declarations:\\n{}","messagePattern":"Type checking failed when generating declarations:\\\\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/tools/bundle/mod.rs","lineNumber":469,"sourceCode":"      specifiers,\n      crate::graph_util::BuildGraphWithNpmOptions {\n        is_dynamic: false,\n        loader: None,\n        npm_caching: cli_options.default_npm_caching_strategy(),\n      },\n    )\n    .await?;\n\n  // Run type checker to emit declaration files\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    deno_core::anyhow::bail!(\n      \"Type checking failed when generating declarations:\\n{}\",\n      result.diagnostics\n    );\n  }\n\n  // Index emitted .d.ts files by their original source specifier\n  // TSC emits keys like \"file:///path/to/file.d.ts\" - map them back to source paths\n  let mut dts_by_source: std::collections::HashMap<String, String> =\n    std::collections::HashMap::new();\n  for (file_name, content) in &result.emitted_files {\n    // Map \"file:///path/to/mod.d.ts\" -> normalized source path\n    if let Ok(specifier) = Url::parse(file_name)\n      && let Ok(file_path) = specifier.to_file_path()\n    {\n      let source_path = file_path.to_string_lossy().to_string();\n      dts_by_source.insert(source_path, content.clone());\n    }\n  }","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/cli/tools/bundle/mod.rs#L451-L487","documentation":"deno bundle --declaration runs the TypeScript compiler over the entry's module graph to emit .d.ts files (type_checker.emit_declarations, cli/tools/bundle/mod.rs:460-466). If tsc produces any diagnostics, the run fails with them appended after this message - the same class of errors deno check reports, surfaced from bundling.","triggerScenarios":"Any type error in the entry's graph (TS2322 assignments, TS2339 property access, TS2307 missing modules with types missing); npm/jsr dependencies that ship no or broken types; tsconfig compilerOptions (strictness, lib) making previously-passing code fail.","commonSituations":"Libraries bundling artifacts with --declaration in CI where local editor checks were skipped; a dependency update changing types; strict mode enabled via deno.json compilerOptions turning previously silent issues into errors.","solutions":["Run 'deno check <entry>' and fix the reported type errors there first - it iterates faster than bundling","Ensure npm:/jsr: dependencies expose types (prefer @types/ packages where the base package is untyped)","Loosen the specific code: correct the typing rather than suppressing; as a last resort annotate with @ts-ignore/@ts-expect-error at the exact sites listed in the diagnostics","If the declaration artifact isn't required, drop the --declaration flag from the build step"],"exampleFix":"# before\ndeno bundle --declaration src/lib/main.ts --outdir dist  # fails: Type checking failed when generating declarations\n# after: iterate on errors first, then bundle\ndeno check src/lib/main.ts   # fix everything reported here first\ndeno bundle --declaration src/lib/main.ts --outdir dist","handlingStrategy":"validation","validationCode":"# Validate type-cleanness before the declaration bundle step\ndeno check src/lib/main.ts || { echo 'fix type errors before --declaration'; exit 1; }\ndeno bundle --declaration src/lib/main.ts --outdir dist","typeGuard":null,"tryCatchPattern":"# CI: run declaration bundling only when the graph type-checks\nif deno check src/lib/main.ts; then deno bundle --declaration src/lib/main.ts --outdir dist; else echo 'skipping --declaration: type errors present'; exit 1; fi","preventionTips":["Make 'deno check' a required CI step ahead of any --declaration bundle","Prefer typed dependencies (jsr:, @types/) so the graph has declarations to emit","Keep strictness increases paired with a fix pass in the same change"],"tags":["bundle","declarations","typescript","type-checking"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}