Skip to content
Latchkey

TypeScript "TS7016: Could not find a declaration file" - Fix in CI

A package resolved at runtime but ships no type declarations, and there is no @types/<pkg>. Under noImplicitAny, tsc refuses to import it as any and raises TS7016. Unlike TS2307, the module *is* found - it just has no types.

What this error means

Type-checking fails with error TS7016: Could not find a declaration file for module '<x>'. '<path>' implicitly has an 'any' type. It suggests trying npm i --save-dev @types/<x>.

tsc output
src/legacy.ts:1:21 - error TS7016: Could not find a declaration file for module
'legacy-lib'. '/app/node_modules/legacy-lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/legacy-lib` if it exists.

Common causes

Package ships no types and has no @types

The dependency has no bundled .d.ts and the DefinitelyTyped @types/<pkg> package is not installed (or does not exist).

Untyped local or internal module

A plain JS module (or an internal package without types) imported into TypeScript triggers TS7016 under noImplicitAny.

How to fix it

Install community types if they exist

Terminal
npm install -D @types/legacy-lib

Declare the module yourself

When no @types exists, add an ambient declaration so the import is typed (even if loosely).

legacy-lib.d.ts
// src/types/legacy-lib.d.ts
declare module 'legacy-lib' {
  const value: unknown
  export default value
}

How to prevent it

  • Install @types/* for dependencies without bundled types.
  • Add ambient .d.ts declarations for genuinely untyped modules.
  • Run tsc --noEmit with noImplicitAny in CI to catch untyped imports.

Frequently asked questions

What causes ""TS7016: no declaration file""?
The dependency has no bundled .d.ts and the DefinitelyTyped @types/<pkg> package is not installed (or does not exist).
How do I fix "TS7016: no declaration file"?
Install community types if they exist

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card