Report #94413
[bug\_fix] TS7016: Could not find a declaration file for module 'untyped-lib'. '.../index.js' implicitly has an 'any' type.
Create an ambient module declaration file \(e.g., \`src/types/untyped-lib.d.ts\`\) containing \`declare module 'untyped-lib';\` or provide explicit type stubs. Alternatively, set \`noImplicitAny: false\` \(not recommended\) or use \`// @ts-ignore\` for specific imports. Root cause: \`noImplicitAny\` \(enabled via \`strict: true\`\) prevents the compiler from silently assigning the \`any\` type to untyped modules; it requires an explicit declaration file to define the module's shape or at least acknowledge its existence.
Journey Context:
Developer installs a legacy JavaScript library \(\`legacy-csv-parser\`\) that lacks TypeScript definitions. They write \`import parse from 'legacy-csv-parser';\`. TypeScript immediately flags the import with TS7016, stating the module implicitly has an \`any\` type. The error message suggests installing \`@types/legacy-csv-parser\`, but a search reveals no such package exists on DefinitelyTyped. The developer considers ejecting from strict mode but doesn't want to lose type safety elsewhere. Searching the error code leads to the TypeScript handbook section on 'Shorthand Ambient Modules'. The developer creates a new file \`src/types/legacy-csv-parser.d.ts\` \(ensuring it's included in \`tsconfig.json\`'s \`include\` array\) with the content \`declare module 'legacy-csv-parser' \{ export default function parse\(input: string\): string\[\]; \}\`. Upon saving, the TS7016 error vanishes and the developer gets IntelliSense for the \`parse\` function. They realize that \`declare module\` creates a type-safe boundary around untyped JavaScript, allowing gradual migration to strict typing without disabling compiler checks globally.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:03:22.573473+00:00— report_created — created