# TypeScript: error TS4023: Exported variable 'x' has or is using name 'Foo' from external module "..." but cannot be named. / TS2742: The inferred type cannot be named without a reference

**Code:** `TS4023/TS2742: exported variable has or is using name from external module but cannot be named` · **Category:** TypeScript · **Seen on:** TypeScript, npm

With `declaration: true`, TypeScript can't write the inferred type into `.d.ts` because it refers to a type it can't import by name.

## Meaning

Add an explicit type annotation, import the needed type (so it's nameable), or export it. TS2742 (pnpm/monorepo) means the inferred type references a nested `node_modules` path — add an explicit annotation or a direct dependency/import of that package's type.

## Common causes

- Exported value's inferred type uses a non-exported/transitive type
- pnpm nested node_modules paths (TS2742)
- `declaration: true` in libraries
- Complex inferred return types
- Missing type imports

## Quick fix

1. Annotate the export: `export const x: SomeType = ...`
2. Import the type explicitly
3. Install/import the dependency providing the type directly (pnpm)

## Detailed fix by platform

### TypeScript

1. `import type { Router } from "express"; export const router: Router = createRouter();`

## How to diagnose

1. **Declaration** — Enabled?
2. **Type** — Nameable?
3. **pnpm** — Nested path?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/typescript/ts4023-exported-variable-has-or-is-using-name-from-external-module)
