I've been looking around the web to try and find s nice solution to my problem but so far I have not.
I have a NX monorepo with NextJS and I am trying to create a global types/
folder that can be used by all of my apps and libs.
I had thought this would be quite simple, I would add a folder to the root and put all my .d.ts
files in there. Then in the tsconfig.base.json I would add
"typeRoots": [
"node_modules/@types",
"node_modules/next/types",
"types/"
]
I was hoping it would be as simple as that.
Allowing me to use my typing anywhere within the monorepo without having to import them.
Unfortunately, this didn't work. After lots of messing around I did manage to get it to work but only if the types/
folder was inside of the app, for example:
apps/
/myApp/
/types/ <- types here were detected
types/ <- types here were not detected
tsconfig.base.json
This is no good for me as it would mean I would have to duplicate my types across all apps and libs.
The official recommendation from NX is to add a new lib just to store your types and then import it and use it in each of your apps and libs but this feels really clunky to me. Also, this doesn't really work with the idea of adding it to typeRoots
within the tsbase.config.json
If anyone knows a better way this can be done I would love to hear about it.
Cheers.