Dealing with Untyped Third-Party Libraries
Use @types packages and write manual declarations.
The Problem: Missing Types
Some npm packages do not ship TypeScript declarations and have no @types/ package. TypeScript treats them as any by default, losing type safety at the boundary.
import legacyLib from "untyped-lib"; // legacyLib: any@types Packages
The DefinitelyTyped project provides community-maintained type declarations for thousands of libraries. Search npm for @types/library-name.
npm install --save-dev @types/lodash
npm install --save-dev @types/express
# Now lodash and express have full TypeScript typesAll lessons in this course
- Starting the Migration: allowJs and checkJs
- JSDoc Type Annotations as a Bridge
- File-by-File Conversion Strategy
- Dealing with Untyped Third-Party Libraries