Report #62113
[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.
Explicitly import the type that is being inferred and use it as a type annotation on the exported symbol. For example, \`import type \{ AxiosInstance \} from 'axios'; export const api: AxiosInstance = axios.create\(...\);\`. Alternatively, if the type is internal, use \`typeof\` in the annotation: \`export const api: ReturnType = ...\`.
Journey Context:
Developer is optimizing build times by converting a monorepo to use TypeScript Project References \(\`composite: true\`\). After splitting a package, \`tsc --build\` fails on an exported constant: \`export const client = new PrismaClient\(\)\`. The error is TS2742, complaining that the inferred type cannot be named without a reference to \`../node\_modules/@prisma/client\`. The developer checks that \`@prisma/client\` is in \`dependencies\`. They try adding a JSDoc type annotation, but it doesn't help. They search and find that with \`composite\`, TypeScript generates \`.d.ts\` files for consumers. For the declaration file to reference \`PrismaClient\`, it must be explicitly imported in the source file so the reference path can be resolved. The developer adds \`import type \{ PrismaClient \} from '@prisma/client'\` and changes the export to \`export const client: PrismaClient = new PrismaClient\(\)\`. The build succeeds. They understand that \`composite\` requires explicit type imports for any type exposed in the public API to ensure declaration file portability.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:44:30.156760+00:00— report_created — created