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

Monorepo Jest Type Definition #696

Closed
Oreoz opened this issue Apr 25, 2020 · 1 comment
Closed

Monorepo Jest Type Definition #696

Oreoz opened this issue Apr 25, 2020 · 1 comment
Labels
kind: support Asking for support with something or a specific use case solution: duplicate This issue or pull request already exists topic: monorepo Related to Lerna monorepos

Comments

@Oreoz
Copy link

Oreoz commented Apr 25, 2020

Current Behavior

When you bootstrap a package using TSDX inside a Lerna monorepo, if you open the new package directly code mono/packages/tsdx type definitions of Jest load correctly.

However, when you open the monorepo directly code mono and navigate to a test inside the sub package, VSCode lights up like a Christmas tree.

Desired Behavior

If possible, it would be great to have type definitions when opening the monorepo.

Suggested Solution

I'm terrible at TypeScript bootstrapping, hence why I used TSDX.

Perhaps (most likely) it's something easily fixable on my end, but since everything else worked out of the box, it would be great if that worked too!

Who does this impact? Who is this for?

Monorepo users mainly.

Describe alternatives you've considered

I've tried tweaking the tsconfig.json and creating a new one only for my tests, but didn't get it to work properly.

Only alternative I see now is opening VSCode directly at my package instead of the monorepo, but that doesn't quite fit my workflow most of the time.

Cheers!

@agilgur5 agilgur5 added topic: monorepo Related to Lerna monorepos kind: support Asking for support with something or a specific use case labels Apr 26, 2020
@agilgur5
Copy link
Collaborator

agilgur5 commented Apr 26, 2020

So if you only install tsdx for one package, @types/jest is also only in that one package's node_modules. It's not in your top-level's node_modules, so your test globals aren't detected or typed. You didn't install TSDX at monorepo root, you installed it at package level, so TSDX and any features therein are only present in the specific package you installed it for.

That isn't a bug in TSDX and is more a Lerna support question or a general Node support question. You can install @types/jest at the top-level if you want, if you have Jest set-up there already. Or you can hoist TSDX to the top-level if you want to use it for multiple packages etc. Could also use something like jest-without-globals to explicitly import your Jest globals instead. Lots of options

There's an existing (very popular) issue for a monorepo template already: #122 (I've never used a Lerna monorepo so it's not my realm of expertise; Jared was going to add support for it but never did 😕). And there's also a label for everything monorepo-related. Please make sure to search the issues before reporting a new one.

@agilgur5 agilgur5 added the solution: duplicate This issue or pull request already exists label Apr 26, 2020
@agilgur5 agilgur5 changed the title Monorepo Jest Type Definition - VSCode Monorepo Jest Type Definition May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: support Asking for support with something or a specific use case solution: duplicate This issue or pull request already exists topic: monorepo Related to Lerna monorepos
Projects
None yet
Development

No branches or pull requests

2 participants