denoland/deno · error · AnyError
Type checking failed
Error message
Type checking failed:
{} What it means
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.
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.
Example fix
// before: type error that triggers the diagnostic
export const count: number = parseInt("1"); // ok, but:
export const bad: number = "1"; // TS2322
// after
export const bad: number = parseInt("1"); Defensive patterns
Strategy: validation
Validate before calling
# fail fast on type errors before generating anything
deno check main.ts || { echo "fix type errors first"; exit 1; }
deno cache main.ts Try / catch
output=$(deno cache main.ts 2>&1) || { echo "$output" | grep '^TS[0-9]' ; exit 1; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot generate declarations for files with different…
- Entry point must be a file
- Error getting navigation tree for
- Failed ensuring public API type output is valid.
- No declaration file emitted for entry point
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/098ae781efab8651.
Report an issue: GitHub.
Appendix: source
Thrown at cli/tools/transpile.rs:298
'{}' uses scope '{}' but '{}' uses scope '{}'.\n\
Separate these files into different invocations.",
first_specifier,
first_key,
specifier,
key,
);
}
}
let type_checker = factory.type_checker().await?;
let result = type_checker.emit_declarations(
Arc::new(graph),
root_names,
cli_options.ts_type_lib_window(),
)?;
if result.diagnostics.has_diagnostic() {
anyhow::bail!("Type checking failed:\n{}", result.diagnostics);
}
// Determine the output directory for .d.ts files.
// With -o, place .d.ts next to the output file.
// With --outdir, use the outdir.
// Otherwise, place next to the source file (handled by TSC path).
let output_base_dir = if let Some(output) = &transpile_flags.output {
let output_path = cwd.join(output);
output_path.parent().map(|p| p.to_path_buf())
} else {
None
};
// Write emitted .d.ts files
for (file_name, content) in &result.emitted_files {
// The file names from TSC are specifier-based, convert to output paths
let output_path = resolve_dts_output_path(
file_name,View on GitHub (pinned to 9ad36f7a2c)