Mono repo, include *.d.ts on imports

Viewed 28

Situation:

Our monorepo has 2 workspaces: foo and bar.

foo has the files:

  • src/file.ts
  • src/@types/baz.d.ts

bar workspace imports @monorepo/foo/src/file.

Type-checks work for the foo workspace but not for the bar workspace.

How can I ask typescript to include the appropriate *.d.ts when importing from @monorepo/foo/*?

1 Answers

Found a solution:

foo/tsconfig.json

{
  "compilerOptions": {
    "outDir": "dist",
    "composite": true
  }
}

bar/tsconfig.json

{
  "compilerOptions": {
    "outDir": "dist",
  },
  "references": [
    {
      "path": "../foo",
      "declarationMap": true
    }
  ]
}

Use tsc -b instead of tsc --noEmit

outDir is not required but it will group all the built files in the same folder.

Related