Replies: 1 comment 1 reply
-
we won't make compromises in type safety. So I don't think this will happen |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I know that generating a real ts file helps with type inference in TypeScript, but for projects without TypeScript or where types aren't critical, this feature of virtual imports will become exceptionally convenient. At least the user won't see errors (red marks) in the file when they haven't run the
vite dev/serve
command for the first time. While this is not a big deal, it might be a bit uncomfortable for those with "perfectionist" tendencies.Of course, if types are important, I have another idea to solve this problem. Suppose our virtual module is:
virtual:routeTree.ts
, we can provide general but not strict type declarations in the plugin library, like this:In the specific project using the plugin, during the project startup, a more strict type definition file (for example: route-tree.d.ts) is generated through the vite plugin to override the default broad type definitions provided by the library package.
Then, in our specific project, we can happily use:
import routeTree from "virtual:routeTree.ts"
, while the plugin only needs to do (pseudo code):Uh~~~ The only downside here is that it might be a bit difficult to generate type definition files~~~
Haha, I don't know how feasible and meaningful this matter is, but I still want to bring it up for everyone's reference and discussion. I look forward to its coming!
Beta Was this translation helpful? Give feedback.
All reactions