typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Project references indirect dependencies: Error 2742 Inferred type of xxx ...

Open johnpyp opened this issue 3 weeks ago • 3 comments

Potentially related: https://github.com/microsoft/typescript-go/issues/1034

Steps to reproduce

https://github.com/johnpyp/tsgo-monorepo-reference-issue

Setup

  • package-c: exports MyType interface
  • package-b: project reference to package-c, exports createThing() returning MyType
  • package-a: project reference to package-b only (not package-c), uses createThing() without type annotation

The issue is that package-a reaches package-c types transitively through package-b, but doesn't have a direct project reference to package-c.

Behavior with [email protected]

No error

Behavior with tsgo

packages/package-a/src/index.ts(4,10): error TS2742: The inferred type of 'thing' cannot be named without a reference to '../../package-b/node_modules/package-c/out'. This is likely not portable. A type annotation is necessary.

johnpyp avatar Dec 04 '25 22:12 johnpyp

have same issue with pnpm

safareli avatar Dec 09 '25 19:12 safareli

Likewise

dimitraz avatar Dec 09 '25 19:12 dimitraz

@dimitraz @samdcoding please use the thumbs up instead. It is more considerate of subscribers watching issues.

sanny-io avatar Dec 10 '25 00:12 sanny-io

I had to disable project references with composite: false to fix it.

Some related research from typescript/pnpm repos I did:

  • https://github.com/microsoft/TypeScript/issues/42873#issuecomment-2065572017
  • https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1519138189
  • https://github.com/microsoft/TypeScript/pull/58176#issuecomment-2052698294
  • https://github.com/pnpm/pnpm/issues/7453

I presume it's solely an issue with ts-go, not the original typescript repo?

jordan-cutler avatar Dec 13 '25 22:12 jordan-cutler