Report #22438
[bug\_fix] The inferred type of 'X' cannot be named without a reference to 'Y'. This is likely portable. You may need to add an explicit type annotation. \(TS2742\)
Add an explicit return type annotation to the function or exported constant, or use \`import type \{ Y \} from 'package-b'\` in the file where 'X' is exported to ensure the type reference is explicit. Root cause: TypeScript's type inference creates a type that depends on another package's internal type that isn't explicitly exported or reachable through the public API surface, making the .d.ts file generation impossible without an explicit import/reference.
Journey Context:
Developer is working in a pnpm monorepo with two packages: \`@org/core\` and \`@org/utils\`. In \`@org/utils\`, they have a function \`createHelper\(\)\` that returns an object containing a method whose return type is inferred from a complex generic type in \`@org/core\` \(e.g., \`ReturnType\`\). When they try to build \`@org/utils\` with \`tsc\`, it errors with TS2742 on the exported \`createHelper\` function, stating the inferred type cannot be named without a reference to a specific internal file in \`@org/core\`. The developer is confused because \`@org/core\` is listed in \`dependencies\` and the types work fine inside the function body. They try exporting the type explicitly from \`@org/core\`'s index.ts, but the error persists. They search and find a GitHub issue explaining that TypeScript needs an explicit import of the type dependency to write the .d.ts file. They add \`import type \{ TheSpecificType \} from '@org/core'\` at the top of the file in \`@org/utils\`, even though it's not used in the value space, only as an explicit annotation for the return type of \`createHelper\`. Alternatively, they explicitly type the return of \`createHelper\` as \`HelperInterface\` where \`HelperInterface\` explicitly references the core type. This works because it forces TypeScript to include the necessary import in the generated declaration file, making the type 'portable'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:04:10.620866+00:00— report_created — created