wobsoriano / bun-plugin-dts

A Bun plugin for generating dts files.
MIT License
84 stars 7 forks source link

Throws error for imported assets #3

Closed vveisard closed 1 month ago

vveisard commented 1 year ago

This plugin throws an error when resolving imported assets as described by the Bun documentation here:

Files

// index.ts
import desertViewTowerUrl from './desert/background.jpg'

Output

error TS2307: Cannot find module './desert/background.jpg' or its corresponding type declarations.

Expected Behavior

I would expect this plugin to skip anything that Bun considers to be an asset.

ghost commented 6 months ago

I guess this problem has already been resolved, but just for you,

  1. This is not a problem with this plugin.

This plugin is just for people who want to use the features from dts bundle generator but in Bun. This project just kind of imports all features that we can normally use with that dts bundle generator and imports it as a Bun plugin. That is also the reason why the options in this project look pretty similar to the options in the dts bundle generator, except that we have to put the dts() call stuff inside of the plugins. If you still think there is a problem with this after reading the next thing, then you will have to make an issue on the official repository that this project uses.

  1. You have to write all codes manually again.

If you look at Next.js or any other famous TypeScript frameworks, you will be able to see their tremendous works of just importing all types that the developers might have to use and exporting all imported types again from one file, like this, or this. Also, they never import any files with JPG, PNG or any other images/videos/or assets types because it is impossible to make TypeScript types for them. So, what you probably have to do is to reimport all types, reexport them in a single file without files with those extensions, set that file as the entry point, and run the script for Bun. And do not forget to add this path ./dist/index.d.ts or whatever you set it as to the "types" field in your package.json so that the final file can also be exported out of the node_modules folder.

If you have any questions or something, please comment below.