Report #48025
[bug\_fix] TS2742: The inferred type of 'createRouter' cannot be named without a reference to '.pnpm/.../node\_modules/@trpc/server/dist/...'. This is likely not portable. A type annotation is necessary.
Explicitly import the transitive type dependency and add an explicit return type annotation to the exported function \(e.g., \`export const createRouter = \(\): Router => ...\`\). Root cause: TypeScript's declaration emitter cannot serialize inferred types that depend on packages not directly imported in the current file, especially in monorepos with symlinked dependencies \(pnpm\), as the emitted \`.d.ts\` would contain a non-portable file path.
Journey Context:
Developer is working in a pnpm monorepo with TypeScript project references. They have a package \`@myapp/api\` that builds a tRPC router. They export a function \`export const createRouter = \(\) => createTRPCRouter\(\{ ... \}\)\`. When running \`tsc --build\`, they get TS2742 claiming the inferred type references a deep path inside \`.pnpm/\`. The developer is confused because \`tsc\` clearly resolves the types during compilation. They search the error code and find GitHub issue \#47663. They learn that because \`tsc\` emits declaration files \(\`.d.ts\`\), it needs to write down the type of \`createRouter\`. Since the type is inferred from a transitive dependency \(\`@trpc/server\`\) that isn't explicitly imported in this file, \`tsc\` tries to write the absolute path to the \`.pnpm\` store, which isn't portable. The fix is to explicitly import the type \`import type \{ Router \} from '@trpc/server'\` and annotate the function \`export const createRouter = \(\): Router => ...\`, giving \`tsc\` a portable name to emit.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T11:05:50.747677+00:00— report_created — created