Home > other >  Referencing types in monorepo in sibling directory (going below root)
Referencing types in monorepo in sibling directory (going below root)

Time:01-13

Would someone know how to help to solve a problem of referencing types in a TypeScript monorepo project? Or if it is even possible in the following setting.

The structure is like

.
├── tsconfig.json
├── lib/
│   └── workers/
│       ├── types.ts
│       ├── hello.ts
│       └── tsconfig.json
└── frontend/
    ├── tsconfig.json
    └── openwcMiniflare.ts

where frontend/tsconfig.json references types like import { WorkerMethods, WorkerEvents } from 'workers/types'; with configuration such as (relevant parts, full source enter image description here

BUT! If I change the definition like import { WorkerMethods, WorkerEvents } from '../../lib/workers/types';, then error message tells they're outside of rootDir.

Is structure like this even possible with VS Code?

CodePudding user response:

Well! This is embarrassing, also a bit strange. This configuration does in fact work after I cleaned up node_modules and lock files. I have no idea what could have been the problem and if the cause was about this or doing this cleaning just contributed in such a way the solution works.

In any event, if/when someone looks into this issue, that configuration should work (remembering the usual tsc --build on composite projects and tsc --project <directory>\tsconfig.json or a combination thereof).

  •  Tags:  
  • Related