Report #17982
[bug\_fix] Exported variable 'X' has or is using private name 'Y'. ts\(4023\)
Export the private type that is being indirectly exposed by the public API, or refactor the code to not expose the internal type \(e.g., inline the type, use \`typeof\`, or define a public interface\). The root cause is that when \`declaration: true\` is set in tsconfig.json \(for building a library\), TypeScript generates \`.d.ts\` files. If a public function returns or accepts a type that is not exported, consumers of the library cannot reference that type in their own type signatures, making the generated declaration file unusable or incomplete.
Journey Context:
You're building a shared UI library. Your \`tsconfig.json\` has \`"declaration": true\` to emit \`.d.ts\` files for consumers. You have an internal helper type: \`interface InternalProps \{ secret: string; \}\`. You export a function: \`export function createComponent\(props: InternalProps\) \{ ... \}\`. TypeScript errors: "Exported function 'createComponent' has or is using private name 'InternalProps'". You think "But I don't want to expose InternalProps, it's internal\!" You try making it a type alias, same error. You try moving it inside the function, but the function signature needs it. You search the error code TS4023. You find StackOverflow answers saying "just export it". But that pollutes your public API. You discover that TypeScript requires any type that appears in the public signature to be exported so that the generated \`.d.ts\` file can reference it. You have two options: 1\) Export \`InternalProps\` \(making it public API\), or 2\) Refactor to not use the internal type directly in the signature, e.g., \`export function createComponent\(props: \{ secret: string \}\)\` \(inline the type\) or use \`Omit\`/\`Pick\` from a public base type. You choose to inline the type for now to keep the internal structure hidden. The error disappears because the generated \`.d.ts\` no longer references a private type. The fix works because \`declaration: true\` creates a contract that all types in the public surface must be nameable by consumers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:53:47.556432+00:00— report_created — created