Skip to main content
← Guides

Guide

Packages That Ship TypeScript Types vs 2026

Updated PkgPulse Team6 min read
0

Check whether an npm package ships TypeScript declarations, when to install @types, and how to verify the types.

Contents

TL;DR

Start with declarations bundled in the package. If the import has no declarations, look for the matching @types package on DefinitelyTyped. In both cases, compile the exact import and call your app uses. Bundling makes it possible to release code and declarations together, but the compiler still trusts those declarations to describe the runtime.

Key Takeaways

  • Check the package manifest and the declaration files for the exact entry point you import.
  • With DefinitelyTyped, track the declaration package separately from the runtime dependency.
  • Check types in the app's own compiler configuration. An ESM import and a CommonJS require can resolve to different declarations.
  • Test behavior at runtime when a wrong declaration could hide a breaking change.

Built-In Types vs DefinitelyTyped

Fastify publishes its declarations with fastify. Express publishes its JavaScript separately from @types/express. Install the latter as a dev dependency for an Express app that needs TypeScript declarations. Fastify registry metadata · Express declarations


How to Check Which Type System a Package Uses

Inspect the version from your lockfile. This example uses the current fastify manifest. In an existing project, add the installed version after the package name.

npm view fastify --json | jq '{types, typings, exports}'
npm pack fastify --dry-run --ignore-scripts

Look for a declaration at the entry point you import. TypeScript can also resolve a declaration next to a JavaScript entry point without a types field. If the package has an exports map, check each subpath and the active module resolution mode. Run tsc --noEmit --traceResolution in your app to see the file the compiler selected. The terminal commands show how to inspect the package and compiler. TypeScript module resolution


Major Packages: Built-In Types ✅

Fastify declares its entry point in types. Hono also has an exports map for package subpaths. Check the import you use when a package exposes more than its root. Fastify registry metadata · Hono registry metadata


Packages That Still Need @types/

Express, React and React DOM have declarations in @types/express, @types/react and @types/react-dom. Install the declarations you need for the packages you import. For Node.js built-ins, choose @types/node for the runtime you target.

Modern uuid releases ship their own declarations, and @types/uuid is a deprecated stub. DefinitelyTyped · uuid registry metadata · @types/uuid registry metadata


The Version Mismatch Problem

DefinitelyTyped versions track the upstream major and minor versions they target. The patch number tracks revisions to the declarations. Comparing Express's patch number with the patch number on @types/express therefore won't tell you whether a method is declared. Check the intended version family, compile the specific call and run it against the locked JavaScript package before upgrading either dependency. DefinitelyTyped versioning


How to Count Type Support

A package count needs a defined population and a consistent test for each entry point. A manifest field, a successful compile and a matching @types package answer different questions. When evaluating your own dependencies, check the packages in your lockfile and record how the imports you use resolve.


How to Check Type Quality (Not Just Presence)

// Having types isn't enough — type QUALITY matters

// Red flags in declaration files:
// ❌ Everything typed as `any`
declare function doThing(options: any): any;

// ❌ Missing generics
declare function useQuery(key: string, fn: Function): any;
// Should be:
declare function useQuery<T>(key: string, fn: () => Promise<T>): { data: T | undefined };

// ❌ Types in wrong export location (export default vs export =)
// Causes: "Module has no exported member" errors

// ✅ Good type quality signals:
// - Generics used throughout
// - Return types inferred from input types
// - Utility types used correctly (Partial, Required, Pick, Record)
// - TypeScript strict mode compatibility
// - Types tested in the package's own test suite (dts-jest or tsd)

tsconfig Best Practices with @types/

Use the types option to list packages that should contribute globals. The list does not stop TypeScript from resolving declarations for modules you explicitly import. Older TypeScript versions include visible @types packages by default, while current versions default to an empty list. TSConfig reference

{
  "compilerOptions": {
    "types": ["node", "jest"],
    "skipLibCheck": false
  }
}

This illustrative configuration assumes Node and Jest globals are used and their declaration packages are installed. skipLibCheck: true skips checking declaration files. When two declarations conflict, inspect the resolved files before deciding to skip that check.


Migrating Off DefinitelyTyped

After upgrading a package that now bundles declarations, remove its standalone @types entry if no other code requires it. Reinstall from the updated lockfile and compile the affected imports with tsc --noEmit. If a type disappears, inspect the resolution trace to see which declaration previously supplied it.


What the Published Package Includes

A package can publish declarations from TypeScript source or maintain them alongside JavaScript. Test what the published package actually contains. A declaration in the source repository can be missing from the tarball or unreachable through the exports map.


Maintaining Bundled and Separate Declarations

When code and declarations ship together, teams can review changes to both in the same release. Check whether that release tests declarations for the public APIs you use. With a separate @types dependency, review changes in both release streams during upgrades.

How DefinitelyTyped Actually Works

DefinitelyTyped keeps declaration sources in directories such as types/express. Its tooling publishes them to npm under the @types scope. If a new library API differs from what the compiler accepts, check the installed versions and the declaration file before reporting the issue. The runtime and declaration maintainers can release fixes independently. DefinitelyTyped publishing process

The Declaration File Quality Spectrum

Having TypeScript types in a package does not guarantee those types are useful. Declaration file quality ranges from comprehensive and precise to technically present but practically useless. The worst case is a package whose entire public API is typed as any — TypeScript accepts all usage but provides no safety. This pattern appears in older packages that added types as an afterthought, adding just enough declaration to silence the "could not find a declaration file" error without providing real type safety.

The quality signals to look for are: whether the library uses generics to preserve type information across calls (a useQuery<T> that returns typed T | undefined data is better than any), whether discriminated unions are used for variant results (a result type with { status: 'success', data: T } | { status: 'error', error: Error } is better than a union of optional fields), and whether the types include JSDoc comments that appear in editor hover text. These quality markers distinguish type definitions that actively help you write correct code from type definitions that merely suppress TypeScript errors.

Module Resolution and the exports Field

Under module resolution modes that read exports, use a condition for the declarations that go with each entry point. For a dual-format package, place types before default within each format branch. Use .d.mts and .d.cts to identify the module format explicitly. TypeScript exports resolution

{
  "exports": {
    ".": {
      "import": {
        "types": "./dist/index.d.mts",
        "default": "./dist/index.mjs"
      },
      "require": {
        "types": "./dist/index.d.cts",
        "default": "./dist/index.cjs"
      }
    }
  }
}

This example assumes the build emits all of those files. Check imports from both module formats before publishing.

The @types/node Special Case

@types/node provides declarations for Node.js APIs. Use the release line for the runtime your app must support. A declaration from a newer runtime can let code compile even when the underlying API is missing from production.

Authoring TypeScript Packages: The Modern Standard

Ship declarations for each module format you publish and test the packed package from a consumer project. If you support different TypeScript compiler versions, the handbook documents versioned types conditions in exports and typesVersions for cases where exports is not read. TypeScript package publishing · TypeScript versioned resolution

Practical Evaluation Checklist

  1. Find the exact package version and import path in your project.
  2. Inspect the declaration that TypeScript resolves for that import.
  3. Compile the calls you will use, including one input that the type should reject.
  4. Run the calls whose behavior matters and repeat the check when you update either the library or its declarations.

Compare TypeScript support and package health on PkgPulse.

See also: TypeScript vs JSDoc and TypeScript Adoption Rate Among Top npm Packages, Best TypeScript-First Build Tools 2026.