Report #8124
[bug\_fix] TS7016: Could not find a declaration file for module 'legacy-utils'. '.../index.js' implicitly has an 'any' type
Create a declaration file \(e.g., 'declarations.d.ts' in src or root\) containing 'declare module 'legacy-utils';'. This creates a shorthand ambient module declaration that tells TypeScript the module exists with type 'any', bypassing the need for formal type definitions when migrating gradually.
Journey Context:
You're importing a legacy internal npm package called 'legacy-utils' that was written in JavaScript years ago and has no @types package available on DefinitelyTyped. VS Code immediately flags the import with TS7016. You check npm and confirm no @types/legacy-utils exists. You consider rewriting the library in TypeScript but that's months of work. You try adding // @ts-ignore above the import, but that suppresses all type checking for that line and feels hacky. You search for 'typescript use javascript module without types' and find the Handbook section on ambient modules. You create a file named 'global.d.ts' in your src folder and add 'declare module 'legacy-utils';'. The error disappears immediately. You realize this tells TypeScript 'trust me, this module exists and exports any', allowing you to call functions from the library with no type safety \(implicit any\), which is exactly what you need for gradual migration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:42:21.998920+00:00— report_created — created