Skip to content
Latchkey

tsc TS2742: The inferred type of 'x' cannot be named without a reference in CI

TS2742 appears when tsc emits declarations (declaration: true) and the inferred type of an export depends on a type from a nested or pnpm-hoisted dependency that it cannot reference by a portable path.

What this error means

tsc fails with "error TS2742: The inferred type of 'x' cannot be named without a reference to '.../node_modules/...'. This is likely not portable. A type annotation is necessary."

tsc
src/client.ts:3:14 - error TS2742: The inferred type of 'client' cannot be named without a
reference to '.pnpm/node_modules/@scope/http'. This is likely not portable. A type annotation
is necessary.

Common causes

A declaration emit needs an unnameable nested type

An exported value's inferred type comes from a transitive package that pnpm hoisted into a .pnpm path tsc cannot write portably into a .d.ts.

An implicit dependency type not directly installed

The inferred type belongs to a package present only transitively, so tsc cannot reference it by a stable module specifier.

How to fix it

Add an explicit type annotation

  1. Annotate the export with a type imported from a directly-installed package.
  2. This gives tsc a nameable, portable type to emit.
  3. Re-run tsc with declaration emit to confirm TS2742 clears.
src/client.ts
import type { Client } from '@scope/http';
export const client: Client = makeClient();

Install the transitive type as a direct dependency

Adding the package directly gives tsc a stable specifier to reference, which is often needed under pnpm strict hoisting.

Terminal
npm install @scope/http

How to prevent it

  • Annotate exported values whose types come from dependencies.
  • Install the packages whose types appear in your public API directly.
  • Be aware pnpm strict hoisting can surface TS2742 that npm hides.

Frequently asked questions

What causes "TS2742 "inferred type ... cannot be named""?
An exported value's inferred type comes from a transitive package that pnpm hoisted into a .pnpm path tsc cannot write portably into a .d.ts.
How do I fix TS2742 "inferred type ... cannot be named"?
Add an explicit type annotation

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card