Quramy / lerna-yarn-workspaces-example

How to build TypeScript mono-repo project with yarn and lerna
MIT License
898 stars 94 forks source link

Where can you specify typeRoots? #2

Closed mickdekkers closed 6 years ago

mickdekkers commented 6 years ago

Hey, thanks for making this example project. It's been really helpful.

There's a package I'm trying to work with (execa), but some of the typings are incorrect. I'd like to override the @types/execa typings with my own types in a /package/foo/types folder, at least temporarily. From what I understand, this should be possible through setting the typeRoots property in tsconfig like this:

"typeRoots": [
  "./node_modules/@types",
  "./types/"
]

But I'm not sure which tsconfig file this should be put in. I think I've tried all of them (and restarted vscode in between) but the types in my types folder aren't being picked up. Where can I place the typeRoots property so it can be picked up by vscode and tsc when building?

Quramy commented 6 years ago

Hi.

But I'm not sure which tsconfig file this should be put in.

Do you try put typeRoots to <project_root>/tsconfig.base.json? And you can re-structure your project directory such as :

<project_root>
 + node_modules/
 |  | @types
 |  :  + execa/
 + packages/
 |  + foo
 |  \ bar
 + types/ 
 |  + xxx.d.ts 
 |  + yyy.d.ts
 |   :
 + tsconfig.base.json    <-- put typeRoots entry to this file
mickdekkers commented 6 years ago

Hi, thanks for your reply.

I tried restructuring the project directory as you suggested and putting typeRoots in <project_root>/tsconfig.base.json, but it turns out I misunderstood and typeRoots are only used to resolve /// <reference types=".." /> directives. I used the workaround described here by putting that into <project_root>/tsconfig.json, and my types are detected correctly now 🎉