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

Verifying type imports #2542

Closed
bdwain opened this issue Sep 4, 2022 · 4 comments · Fixed by #2543
Closed

Verifying type imports #2542

bdwain opened this issue Sep 4, 2022 · 4 comments · Fixed by #2543

Comments

@bdwain
Copy link
Contributor

bdwain commented Sep 4, 2022

This one is similar to #1678 I think, but I'm interested in making this an error for no-extraneous-dependencies

import type { MyType } from 'my-missing-dep`

the situation where this comes up for me is in a monorepo with yarn workspaces, specifically for internal dependencies, but I guess I don't see why it needs to be limited to those. I have scenarios where I build some packages but not others, and that is determined by the package.json dependency tree. I tested in my project and I can get a missing package.json dependency to still build for a type import, which is where a lint rule would come in handy

Here's an example. If package A imports from package B, but forgets to mark it as a dependency in package.json, normally specifying that I want to build B won't build A either, so this wouldn't need a lint rule because it'd break. But if A happens to get built for another reason (it was already built and never deleted, or package C is also being built, which specifies a dep on A), it could mask the build/runtime error that I would get for missing the dependency. That's where the lint rule would come into play by making it clear at build time when I am missing the dependency.

This applies to types as well regular imports, so I think having an option to enable the check for those would be useful. I'm not 100% sure why it would make sense to ever disable TBH, so I kind of feel like it should be on by default, or not even an option, but that can be a separate question since I know it's a breaking change.

Thoughts?

@ljharb
Copy link
Member

ljharb commented Sep 4, 2022

I agree that an option for this makes perfect sense.

@ljharb
Copy link
Member

ljharb commented Sep 4, 2022

(obviously if we ever have a semver-major, we'd want to turn it on by default)

@bdwain
Copy link
Contributor Author

bdwain commented Sep 4, 2022

great! I'll have a pr up soon

@bdwain
Copy link
Contributor Author

bdwain commented Sep 4, 2022

#2543

@ljharb ljharb closed this as completed in 395e26b Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants