Skip to Content
Install @types for a Library That Ships No Types
Intermediate
0 likes
Tutorials

Install @types for a Library That Ships No Types

Reproduce the missing declaration error, check whether the library has its own types, install the @types package and prove the types work. After this, you know the fallback when no types package exists.

You install a package, import it, and TypeScript refuses with an error about a declaration file. This page walks the exact steps to fix it, using express as the example because it ships no types of its own. If you want to know why types and code are separate packages, and what to do when the types are wrong, read the lesson on @types packages in the course. This is only the fix.

Step 1: reproduce the error

npm pkg set type=module
npm install express
added 65 packages, and audited 67 packages in 1s
import express from "express";

const app = express();

app.get("/", (req, res) => {
  res.send("ok");
});
app.ts(1,21): error TS7016: Could not find a declaration file for module 'express'. '/path/to/project/node_modules/express/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/express` if it exists or add a new declaration (.d.ts) file containing `declare module 'express';`
app.ts(5,15): error TS7006: Parameter 'req' implicitly has an 'any' type.
app.ts(5,20): error TS7006: Parameter 'res' implicitly has an 'any' type.

The first error is the one that matters. The other two follow from it: express is any, so the callback parameters have nothing to be inferred from. The path in the message is your own project folder.

Step 2: check whether the library has its own types

npm view express types

If the package has its own declaration file, this prints its path, and you are done: the types come with the library and the problem is elsewhere, for instance a moduleResolution setting. For express it prints nothing, so go on.

Step 3: install the matching @types package

The name is always @types/ plus the library name.

npm install --save-dev @types/express
added 11 packages, and audited 78 packages in 1s

Two naming rules to remember. A scoped package @scope/name becomes @types/scope__name, with two underscores. And the package has to exist. If npm answers 404 Not Found, nobody has written types for it.

Step 4: check the types are really being used

Compile the same file again.

import express from "express";

const app = express();

app.get("/", (req, res) => {
  res.send("ok");
});

Nothing is printed, so it is clean. To be sure the checking is real and not just silent, break something on purpose.

import express from "express";

const app = express();

app.get("/", (req, res) => {
  res.sendd("ok");
});
app_typo.ts(6,7): error TS2551: Property 'sendd' does not exist on type 'Response<any, Record<string, any>, number>'. Did you mean 'send'?

If a typo in a method name is an error, the types are working. The compiler even suggests send.

Step 5: if no @types package exists

Add a file with one line, and tell tsc about it. A project with a tsconfig.json picks it up from the include list, and on the command line you name it.

declare module "some-old-library";

Everything from that library is any now. It is a stopgap. Write real declarations for the three functions you use as soon as you can.

⚠ Warning: Do not put @types packages in dependencies. They are only read by the compiler, so --save-dev is right. Putting them in dependencies ships them to production for nothing.

Common mistakes

  • Installing @types/express without installing express. The types are not the library.
  • Installing @types/x for a library that already has its own types. Check with npm view x types first.
  • Using declare module "x"; as the permanent answer.
  • Mixing a very old @types package with a new library version. If calls that exist are reported as missing, compare the versions.

Related course: TypeScript Intermediate.

About

Reproduce the missing declaration error, check whether the library has its own types, install the @types package and prove the types work. After this, you know the fallback when no types package exists.

Responsible
Christopher R
Last Update
10/13/2026
Reading Time
4 min
Was this helpful?
​ 0 ​ 0

Comments (0)

Sign in to comment

No comments yet.