Report #23111
[bug\_fix] TS2742: The inferred type of 'X' cannot be named without a reference to 'Y'. This is likely not portable. A type annotation is necessary.
Add an explicit return type annotation to the exported function \(e.g., \`export function createClient\(\): ClientType \{ ... \}\`\), and ensure that any types used in that annotation are exported from the public API entry point. Alternatively, re-export the internal types from the main index.ts so TypeScript can reference them without reaching into node\_modules internals.
Journey Context:
You just finished refactoring a monorepo utility function to infer its return type from a Zod schema parser, feeling clever about avoiding manual type maintenance. You run \`tsc --build\` expecting success, but instead hit TS2742 on the package boundary. Confused, you search the error message and find GitHub issues mentioning 'portable' types. You try adding \`declarationMap: true\` to tsconfig, which changes nothing. You then try exporting the inferred type explicitly from your index.ts, but the error persists because the inferred type still references internal paths. You descend into the node\_modules, realizing TypeScript is trying to write a .d.ts file that references \`@internal/types\` via a pnpm symlink path, which won't exist for consumers. Finally, you explicitly annotate the function return type with an interface you've explicitly defined and exported, breaking the inference chain. The error vanishes because the .d.ts now contains a portable reference instead of a file-system dependent path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T17:12:07.533075+00:00— report_created — created