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."
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
- Annotate the export with a type imported from a directly-installed package.
- This gives tsc a nameable, portable type to emit.
- Re-run tsc with declaration emit to confirm TS2742 clears.
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.
npm install @scope/httpHow 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.