Issues with TypeScript types not being hoisted #5535
Replies: 6 comments 3 replies
-
@zkochan Any thoughts on this? It's still a pain point for me and it seems like it must be a common issue unless I'm holding something wrong. |
Beta Was this translation helpful? Give feedback.
-
I think Also, we setup renovate bot to bump our deps, and he does a great job batching |
Beta Was this translation helpful? Give feedback.
-
I am also running into this issue. |
Beta Was this translation helpful? Give feedback.
-
@zkochan I just ran into this today with both 9.15.9 and 10.8.1. specifically, I also ran into this with
Secondarily, toggling |
Beta Was this translation helpful? Give feedback.
-
I'm hitting the same issue. My build doesn't succeed even if I use both |
Beta Was this translation helpful? Give feedback.
-
These types should be in dependencies. Probably peer dependencies. This module.exports = {
hooks: {
readPackage (pkg) {
if (pkg.dependencies['react'] || pkg.peerDependencies['react']) {
pkg.peerDependencies['@types/react'] = '*'
}
return pkg
}
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It is relatively common for a dependency's types to import their own dependency's types. In a repo with pnpm that is not hoisting packages, this leads to issues with TypeScript being unable to find these types, resulting in
any
types and sometimes errors. It seems like the main way people are fixing this issue is withpublic-hoist-pattern
. However, the list just keeps growing as I bump into issues. A pattern like@types/*
covers some of them, but there are plenty of other common packages with issues, like:@types/react
imports types fromcsstype
@sentry/browser
imports types from@sentry/types
and@sentry/core
msw
imports types from@mswjs/interceptors
and othersThe less that
@types
is used (which is a good thing overall for the ecosystem and the direction we are going) the worse this problem gets. Adding all of these inner dependencies as direct dependencies also seems like a headache (what do you do with versions / upgrades?). These are not peer dependencies so there's no visibility of issues unless there are compile errors or you bump into an unexpected wall looking through types.How are others approaching this issue? While I appreciate the overall philosophy of not hoisting packages, this issue is a consistent sticking point.
Beta Was this translation helpful? Give feedback.
All reactions