Skip to content
Latchkey

tsc TS4023: Exported variable 'x' has or is using name 'y' but cannot be named in CI

TS4023 appears during declaration emit when an exported value's inferred type uses a type that is not exported from its module, so tsc cannot write a .d.ts that names it.

What this error means

tsc fails with "error TS4023: Exported variable 'x' has or is using name 'y' from external module \"...\" but cannot be named." while building with declaration: true.

tsc
src/index.ts:5:14 - error TS4023: Exported variable 'store' has or is using name 'InternalState'
from external module "./state" but cannot be named.

Common causes

The inferred type is defined but not exported

The exported value depends on a type that the source module declares privately, so the generated declaration cannot reference it.

Declaration emit needs every referenced type to be nameable

When declaration is on, tsc must name every type in the public API; a non-exported helper type breaks that.

How to fix it

Export the referenced type

  1. Export the type named in the error from its module.
  2. Or add an explicit annotation that uses an already-exported type.
  3. Re-run tsc with declaration emit to confirm it clears.
src/state.ts
// state.ts
export interface InternalState { /* ... */ }

Annotate the export with a public type

Give the export an explicit type that tsc can name, instead of letting it infer a private one.

src/index.ts
import type { PublicState } from './state';
export const store: PublicState = makeStore();

How to prevent it

  • Export types that appear in your public API surface.
  • Annotate exported values rather than relying on inference of private types.
  • Build with declaration: true locally to catch emit errors early.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →