BeCuriouzLearn something new every day
When a Library Ships No Types
💡 For an untyped library, look for an @types package first, then write a minimal .d.ts declaring only what you use — reach for blanket any only as a last resort.
You run npm install some-old-lib, import it, and TypeScript lights up red: Could not find a declaration file for module 'some-old-lib'. The library is plain JavaScript with no bundled types, and no matching @types package on DefinitelyTyped (the community type repository you learned to pull from with npm i -D @types/...). You have three escalating strategies.
First, check for community types. Try npm i -D @types/some-old-lib. Many popular JS libraries have hand-written types maintained separately. If that exists, you're done — real IntelliSense and checking for free.
Second, if none exist, write a minimal ambient declaration. Create a .d.ts file and declare the module. The quick escape hatch types the whole module as any, which silences the error but gives zero safety:
// types/some-old-lib.d.ts
declare module 'some-old-lib';Better: declare only the shape you actually use, so those calls stay type-checked:
declare module 'some-old-lib' {
export function greet(name: string): string;
export const version: string;
}Third, escape locally at the call site when you just need one function. require (or an as any cast) contains the untyped-ness to a single line instead of leaking any everywhere. Prefer a scoped declaration over any whenever the library is used more than once — a 10-line .d.ts you write in five minutes pays for itself across every call.