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>.
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
npm install -D @types/legacy-libDeclare the module yourself
When no @types exists, add an ambient declaration so the import is typed (even if loosely).
// 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.tsdeclarations for genuinely untyped modules. - Run
tsc --noEmitwithnoImplicitAnyin CI to catch untyped imports.