Where can I put custom T…

2 minute read

Where can I put custom TypeScript definitions?

Responses:

Usually you put types next to whatever code they’re typing.

If you’re creating types that are shared across apps/ libs that aren’t directly sharing code, you can create a lib that just has types

i am trying to override a type from node_modules

it seems it is correct, but I can’t find a way to verify they are being imported or no

I created a new file, then reference it from tsconfig.files options in the app configuration

It works

But VSCode TS server can’t see it

It still complains about the previous error

vs code uses the tsconfig.json file, not the tsconfig.app.json

but tsconfig.app.json and tsconfig.spec.json inherit settings from tsconfig.json

tsconfig.json in the root?

The root file is used for the whole repo, but I think vscode will override the root settings for any folder that has another tsconfig.json file in it

so if you want the types to apply to the whole repo, put it in the root - otherwise put it in individual apps/libs

if you find yourself editing lots of config files, you probably should use a different solution

uhmm, still doesn’t work. I have right now: /tsconfig.json with "files": ["./types/index.d.ts"], and "typeRoots": ["node_modules/@types", "./types"],

Nothing in apps/app/tsconfig.json .

Both nx serve command and VSCode TS server complains about the error

But if I put "files": ["../../types/index.d.ts"], in apps/app/tsconfig.json now nx serve is fine, but of course VSCode TS server doesn’t know about it

maybe it is the wrong way to reference it?

is the error in vs code for a file that is inside of apps/app or is it in a different lib?

actually, the actual error comes from /libs/lib , let me try to put it there

that’s why vs code is complaining. the tsconfig.json file only applies to the folder it is in from vs code’s perspective

even though webpack’s serve uses the app tsconfig for all the code from every library it pulls in

very stupid error, yes, it works perfectly fine now

thanks a lot

not stupid. It’s not very intuitive that the two different processes behave in different ways

uhmm, yeah

I ran into another problem now

I put the config in libs/lib/tsconfig.json that makes VSCode happy, but now when running the app it again complains about it

should I copy the config to apps/app/tsconfig.json too?

yep, copying it to the app config fixes the error when running nx serve

Updated: