TS7016: Could not find a declaration file for module
Fix TypeScript error TS7016 'Could not find a declaration file for module'. Learn to install @types, create custom .d.ts files, and configure typeRoots.
What Does This Error Mean?
TypeScript error TS7016 occurs when you import a JavaScript module that has no type declarations (.d.ts files). TypeScript needs type information for all imported modules when noImplicitAny is enabled. Without declarations, TypeScript does not know the shape of the module's exports.
Common Causes
The npm package does not include bundled TypeScript declarations
No corresponding @types/package exists for the library
The @types/package is not installed or is an incompatible version
A local JavaScript module lacks a .d.ts declaration file
typeRoots or types in tsconfig.json does not include the right paths
The module uses 'export default' but you imported it incorrectly
How to Fix It
Install @types if available
Most popular libraries have type definitions on DefinitelyTyped.
# Install type definitions npm install --save-dev @types/lodash npm install --save-dev @types/react npm install --save-dev @types/express # Check if types exist at: # https://www.npmjs.com/search?q=%40types%2Fpackage-name
Create a custom declaration file
Create a .d.ts file to declare the module's types.
// custom.d.ts (in your project root or a types folder)
declare module "some-legacy-lib" {
export function doSomething(input: string): void
export const VERSION: string
export default class LegacyAPI {
constructor(options: Record<string, unknown>)
run(): Promise<boolean>
}
}
// Also include in tsconfig.json
// "include": ["src/**/*", "custom.d.ts"]Use a quick ambient declaration
For quick fixes, declare the module as any to bypass type checking.
// global.d.ts declare module "some-untyped-lib" // Module typed as any // This suppresses TS7016 but gives no type safety import someLib from "some-untyped-lib" // someLib is typed as any
Configure typeRoots in tsconfig
Ensure TypeScript knows where to look for type declarations.
{
"compilerOptions": {
"typeRoots": [
"./node_modules/@types", // Default location
"./src/types" // Custom types folder
],
"types": ["node", "express"], // Auto-include specific @types
"skipLibCheck": true // Skip checking .d.ts files (faster)
}
}Related Tools
Use these tools to debug and fix this error:
Related Errors
Other common errors in this category:
TS2304: Cannot find name
Fix TypeScript error TS2304 'Cannot find name'. Learn how to declare types, install type definitions, and configure tsconfig.json properly.
TS2339: Property does not exist on type
Fix TypeScript error TS2339 'Property does not exist on type'. Learn to type objects correctly, use type assertions, and narrow types with guards.
TS18048: 'x' is possibly 'undefined'
Fix TypeScript error TS18048 'is possibly undefined'. Learn to use optional chaining, nullish coalescing, and strict null checks correctly.
TS2683: this implicitly has type any
Fix TypeScript error TS2683 'this implicitly has type any'. Learn how to type this in callbacks, use arrow functions, and configure noImplicitThis.
Frequently Asked Questions
Why do some packages not need @types?
Some packages include their own TypeScript declarations (bundled in the package or published as .d.ts files). Check the package's package.json for 'types' or 'typings' field. Modern libraries written in TypeScript often ship declarations.
What if no @types package exists?
You can either: (1) create a custom .d.ts file, (2) use `declare module 'name'` to type it as any, (3) set skipLibCheck to true, or (4) contribute types to DefinitelyTyped for the community.