oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.75k stars 2.73k forks source link

Automatically install type definitions #6493

Open shadskii opened 1 year ago

shadskii commented 1 year ago

What is the problem this feature would solve?

Installing a package in a typescript project is typically a three step operation because of external type definitions. You have to install the package, check if it ships with types, and if it doesn't install the types from DefinitelyTyped. This can annoying and it seems like something your package manager should handle for you.

This is definitely a pain point for many devs because the Typescript LSP has a warning for it

Try npm i --save-dev @types/<package> if it exists or add a new declaration (.d.ts) file

What is the feature you are proposing to solve the problem?

Bun should add an optional flag to automatically install the type definitions for a package if the package doesn't ship with them. The types field in package.json could probably be used for this.

bun add <package> --includeExternalTypes

What alternatives have you considered?

https://github.com/ewgenius/typac

paperdave commented 1 year ago

i like this idea, and it's definitely something i've thought about before.

we could implement this by doing a similar comptime hashmap approach as to what our default trusted dependency allow list uses. this would make it very fast to find if there is a package has types (no network request needed), but at the cost of very new packages not being present.

the question is when do we want to automatically install type defintions, maybe an option in bunfig? and/or --types/--save-types -t or something. @colinhacks what do you think about the interface for this?

ghiscoding commented 1 year ago

It might be unrelated but somehow it makes me thing of npm optionalDependencies and peerDependenciesMeta