Report #71746
[bug\_fix] TS2742: The inferred type of 'createUser' cannot be named without a reference to '../../node\_modules/.prisma/client'. This is likely not portable. A type annotation is necessary.
Add an explicit \`import type \{ User \} from 'prisma-client'\` at the top of the file \(even if unused\), or add an explicit return type annotation to the function.
Journey Context:
Developer is building a library in a monorepo \(pnpm workspace\) that internally uses Prisma \(or Zod, tRPC, etc.\). They export a function \`createUser\` that returns the result of a Prisma query. When building the package with \`declaration: true\`, TypeScript throws TS2742. The error indicates that the inferred return type references types deep inside \`node\_modules\` that aren't explicitly imported. The developer tries adding the external package as a dependency, but the error persists because the specific internal path \(like \`.prisma/client\`\) isn't exported. They try to manually write a return type but struggle because the Prisma type is complex and generated. The breakthrough comes when they realize that TypeScript's declaration emit requires explicit imports for any type that appears in the public API. By adding \`import type \{ User \} from '@prisma/client'\` \(even if \`User\` isn't directly used in the value space, only its shape inferred\), TypeScript can reference \`User\` in the \`.d.ts\` file instead of trying to inline the complex inferred type from deep within node\_modules. Alternatively, explicitly annotating the function return type as \`Promise\` solves it by removing the need for inference.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T03:00:44.224688+00:00— report_created — created