Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting "typeRoots" in tsconfig.json for jest #1820

Closed
jangxyz opened this issue Feb 19, 2021 · 4 comments · Fixed by redwoodjs/redwoodjs-com-archive#602
Closed

Setting "typeRoots" in tsconfig.json for jest #1820

jangxyz opened this issue Feb 19, 2021 · 4 comments · Fixed by redwoodjs/redwoodjs-com-archive#602

Comments

@jangxyz
Copy link
Contributor

jangxyz commented Feb 19, 2021

I am trying to make vscode understand describe, it and etc for test files, but following the document on typescript did not help.

image

Googling around for couple of hours, I found out that setting compilerOptions.typeRoots option to something else prevents from finding jest types.

From the tsconfig docs:

By default all visible ”@types” packages are included in your compilation. Packages in node_modules/@types of any enclosing folder are considered visible. For example, that means packages within ./node_modules/@types/, ../node_modules/@types/, ../../node_modules/@types/, and so on.

If typeRoots is specified, only packages under typeRoots will be included.

typeRoots is currently set to "../.redwood", which I guess is mainly for types built by redwood like routes, but this is blocking the default behavior.

I have actually succeeded on removing errors by commenting out the typeRoots option.

image

(Which I guess means that I can't use named routes)

I don't know if I can set the default behavior of recursively searching for node_modules/@types, but I'm assuming setting only for the root directory will be fine for redwood?

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

This is the same issue with #1400 (comment) . I don't know if others are having same issues -- vscode errors seem to pop all over the place. If it is a common issue, I wonder if this can be included in the docs.

@Tobbe
Copy link
Member

Tobbe commented Feb 19, 2021

"typeRoots": ["../.redwood", "../node_modules/@types"], looks good to me. But I'd wait for @peterp and/or @dac09 to comment as well.

If they don't see any problems with this it should definitely be added to https://redwoodjs.com/docs/typescript#web

@peterp
Copy link
Contributor

peterp commented Feb 27, 2021

👍 This is the way.

@peterp
Copy link
Contributor

peterp commented Feb 27, 2021

@jangxyz Would you be keen to open a PR for this?

@realStandal
Copy link
Collaborator

Ran into this as well and just wanted to make sure API's tsconfig isn't left out of the party :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants