denoland/deno · error · anyhow::Error
Type checking failed: {}
Error message
Type checking failed:
{} What it means
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.
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 89f33cbef2)
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
Example fix
// before (mod.ts)
export function add(a: number, b: string) { return a + b; }
// after
export function add(a: number, b: number): number { return a + b; } Defensive patterns
Strategy: try-catch
Validate before calling
# run the same type-check first; only transpile on a clean pass deno check src/*.ts && deno transpile --declaration src/*.ts --outdir dist
Try / catch
# bash wrapper: surface diagnostics, fail loudly if ! output=$(deno transpile --declaration src/mod.ts --outdir dist 2>&1); then echo "$output" | sed -n '/Type checking failed:/,$p' exit 1 fi
Prevention
- 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
When it happens
Trigger: Any TypeScript type error in the input files (or their imports) while `--declaration` is active.
Common situations: 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.
Related errors
- No emittable files found. Only TypeScript/JSX/TSX files can
- Type checking failed.
- Found {} problem{}
- No input files specified
- Cannot use --output with multiple input files. Use --outdir
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/098ae781efab8651.
Report an issue: GitHub.