πŸ”§ Error Fixes
Β· 1 min read

TypeScript Declaration File Missing β€” How to Fix .d.ts Errors


Could not find a declaration file for module 'some-package'.
'some-package' implicitly has an 'any' type.

TypeScript needs type definitions (.d.ts files) for JavaScript packages. Some packages don’t include them.

Fix 1: Install @types Package

# Most popular packages have community types
npm install -D @types/express
npm install -D @types/lodash
npm install -D @types/node

Fix 2: Create a Declaration File

// src/types/some-package.d.ts
declare module 'some-package';

// Or with basic types
declare module 'some-package' {
    export function doSomething(input: string): void;
    export default function main(): void;
}

Fix 3: Add to tsconfig Include

// tsconfig.json β€” make sure TypeScript sees your .d.ts files
{
    "compilerOptions": {
        "typeRoots": ["./node_modules/@types", "./src/types"]
    },
    "include": ["src/**/*"]
}

Fix 4: Package Has Types But TypeScript Can’t Find Them

// Some packages export types differently
// Check the package's package.json for "types" or "typings" field

// If using moduleResolution: "bundler"
{
    "compilerOptions": {
        "moduleResolution": "bundler"  // Finds more type exports
    }
}

Fix 5: Suppress the Error

// Quick fix β€” not recommended long-term
// @ts-ignore
import something from 'untyped-package';

// Or allow implicit any for specific modules
// tsconfig.json
{
    "compilerOptions": {
        "noImplicitAny": true  // Keep this
    }
}
// And create: src/types/untyped-package.d.ts
// declare module 'untyped-package';

Related: What is TypeScript Β· T3 Env Validation Fix Β· Typescript Strict Mode Errors Fix

πŸ“˜