Open aaditmshah opened 1 year ago
@aaditmshah
This is specific to better-typescript-lib
, but from what I see in the node_modules
output, it only contains TypeScript type definitions. This means it can be directly imported in tsconfig.json
. This is quite a forceful workaround, but it allows better-typescript-lib
to work with Bun.
{
// ...
"include": ["node_modules/better-typescript-lib/node_modules/@typescript/**/*.d.ts"]
// ...
}
What is the problem this feature would solve?
Bun, like pnpm, doesn't automatically hoist packages to the root
node_modules
folder. This is the right thing to do. However, there are a handful of scenarios where we genuinely do need to hoist transitive dependencies. One of those scenarios is when we use thebetter-typescript-lib
package.This package, as the name describes, provides better type definitions for the built-in typescript libraries. For example, it provides stricter type definitions for
JSON.parse
,JSON.stringify
, andfetch().json()
, which helps developers catch more bugs at compile time. All you need to do to use this library is install it. It provides the type definitions as transitive dependencies.These transitive dependencies, such as
@typescript/lib-es5
, are hoisted to the rootnode_modules
folder by package managers like yarn and npm. And, when the TypeScript compiler sees@typescript/lib-*
packages in the rootnode_modules
folder it replaces the built-in type definitions for that library with the type definitions provided by the package. For example, the type definitions ines5.d.ts
would be replaced by the type definitions provided by@typescript/lib-es5
.Unfortunately, because bun doesn't hoist packages, we can't use
better-typescript-lib
with bun. This is a shame, becausebetter-typescript-lib
is an indispensable package for me. I ❤️ both bun andbetter-typescript-lib
. It would be awesome if I could use both of them together.References
better-typescript-lib
: How it workslib
fromnode_modules
What is the feature you are proposing to solve the problem?
Like bun, pnpm also doesn't automatically hoist packages to the root
node_modules
folder. However, it does provide an escape hatch,public-hoist-pattern
, which can be used to hoist only certain packages. Thus, we can usebetter-typescript-lib
with pnpm by adding the following line to our.npmrc
file.I especially like this solution, because we're being explicit about which packages we want to hoist. And, as the Zen of Python states, "Explicit is better than implicit." It would be awesome if bun also implemented the
public-hoist-pattern
config option. Implementing something likepublic-hoist-pattern
in thebunfig.toml
file would be the easiest way to enablebetter-typescript-lib
to be used with bun.References
better-typescript-lib
: Installation with pnpmWhat alternatives have you considered?
There are three alternatives here.
better-typescript-lib
. If I want to continue using bun then I'd have to give up on usingbetter-typescript-lib
, which is currently a deal-breaker for me.better-typescript-lib
to somehow work with bun. As one of the contributors of thebetter-typescript-lib
package, I could try to find a solution to makebetter-typescript-lib
work with bun. However, I have absolutely no idea how to make it work with bun. If there's a way to makebetter-typescript-lib
work with bun by making a change inbetter-typescript-lib
itself, then I'm all ears.