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

Type conflicts between @types/jest and jest #1938

Closed
villasv opened this issue Sep 10, 2020 · 8 comments
Closed

Type conflicts between @types/jest and jest #1938

villasv opened this issue Sep 10, 2020 · 8 comments

Comments

@villasv
Copy link

villasv commented Sep 10, 2020

💬 Questions and Help

I've just realized that the global jest variables in my project are being typed using @types/jest, which is installed as a dependency by ts-jest. On the other hand, I wanted to use the official jest types as they are a bit more up to date with my needs (e.g. beforeAll returning void instead of any).

Is this intended behavior? Or more importantly, can I work around it and make the globals types also come from jest?

@villasv
Copy link
Author

villasv commented Sep 10, 2020

Ah, I see this is being caused by #1859. @types/jest was promoted to a real dependency 🤔

If a single function is responsible for pushing @types/jest as a dependency for everyone, maybe that one typing can be copied over to get rid of the hard dependency?

@villasv
Copy link
Author

villasv commented Sep 10, 2020

Seems relevant too: jestjs/jest#10118

@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 11, 2020

hmm I thought if types in tsconfig.json doesn't contain jest, the conflict shouldn't be there ?

Actually we already discussed with jest team about moving the mocked function to jest, see jestjs/jest#9534

@villasv
Copy link
Author

villasv commented Sep 11, 2020

hmm I thought if types in tsconfig.json doesn't contain jest, the conflict shouldn't be there ?

My types and typeRoots option are unset. Maybe manually listing type roots will help? Not sure, I don't understand a lot about tsconfig.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 11, 2020

I think you can override types by specifiying which ones you want to use, also typeRoots can be overridden too

@villasv
Copy link
Author

villasv commented Sep 11, 2020

Setting types: ["node"] doesn't help, will try excluding @types/jest from typeRoots.

@villasv
Copy link
Author

villasv commented Sep 11, 2020

Well, removing "node_modules/@types" from typeRoots will remove the @types/jest types from my project, but that's not a viable solution because it also gets rid of types for node and other libraries :-/

I don't understand why not listing jest in types didn't work.

@villasv
Copy link
Author

villasv commented Sep 11, 2020

Ah, that's because jest-extended also depends on @types/jest :-(

I guess I'm just going to have to live with this conflict then. Since my expect typing has to come from @types/jest for accurate jest-extended types, but my before/after typing has to come from @jest/globals to have accurate return values.

@villasv villasv closed this as completed Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants