Report #15910
[bug\_fix] TS7016: Could not find a declaration file for module 'legacy-js-lib'. '.../index.js' implicitly has an 'any' type.
Create an ambient module declaration file \(e.g., 'declarations.d.ts' or 'types/legacy-js-lib.d.ts'\) containing 'declare module "legacy-js-lib";' \(or with detailed types\), and ensure 'typeRoots' in tsconfig includes the directory or the file is in the project scope.
Journey Context:
Developer installed a niche npm package from 2015 that has no TypeScript support. They imported it: import \* as legacy from 'legacy-js-lib'. TypeScript immediately flagged TS7016, saying the library implicitly has type any because no declaration file was found. The developer first tried setting 'noImplicitAny': false in tsconfig, which worked but disabled type safety for the entire codebase. They then searched for @types/legacy-js-lib on npm, but it didn't exist. They discovered they could write their own declaration. They created a file src/types/legacy-js-lib.d.ts with the content: declare module 'legacy-js-lib' \{ export function doSomething\(\): void; \}. However, TS still showed the error. They realized tsconfig.json had 'typeRoots': \['./node\_modules/@types'\] which excluded their custom types folder. They either added './src/types' to typeRoots or moved the .d.ts file into the project root and removed the restrictive typeRoots. The error disappeared and they now had typed the library. The fix works because ambient module declarations tell the TypeScript compiler the shape of untyped JavaScript modules, and the compiler must be configured to discover these .d.ts files via the project includes or typeRoots.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:20:30.451727+00:00— report_created — created