Report #21242
[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 'import type \{ ReferencedType \} from 'external-package'' statement in the file, even if the value is not used at runtime, to make the type reference explicit for declaration emit.
Journey Context:
Developer exports a function from a library that returns an inferred type derived from a parsing library like Zod \(e.g., 'z.infer'\). TypeScript throws TS2742, complaining it cannot name the inferred type without referencing the internal 'z' types. The developer tries to write out the full return type annotation manually, but it's a massive complex object. They realize the issue is that TypeScript's declaration emit needs to reference types from 'zod' in the generated .d.ts file, but there's no explicit import of those specific internal types in the source file. The fix is to add 'import type \{ ZodType \} from 'zod'' \(or similar internal types\) even if unused, which gives TypeScript an explicit reference to use in the declaration file. This makes the type 'portable' because consumers of the .d.ts file can resolve the reference.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T14:03:45.939205+00:00— report_created — created