-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve declare module wildcards so that they can match parts of a path more like a glob #38638
Comments
+1 This is a problem that loaders for most of JS bundlers like Webpack or Vite have. I wrote a Vite plugin that loads SVG assets as React components and have the following module declaration: declare module '*.svg?component' {
...
} What I would really want is simply... declare module '*.svg?component*' {
...
} ...to allow the addition of asset specific parameters as part of the query, like this: import Logo from 'graphics/logo.svg?component&memo&titleProp=true'; |
Related questions on stack overflow: |
Any progress/update on this? Tools like |
I'm also using declare module "*&imagetools" {
const out;
export default out;
} import Image from '$lib/images/profile.jpg?w=50&h=50&format=webp&imagetools' Still, it would save some unnecessary code to have the ability to write complex wildcards. |
It would be great if we could do like |
Another tool that needs this is Instead of
|
I just ran into the issue that |
Search Terms
global module match glob path
Suggestion
Improve the declare module wildcards so that they can be used multiple times in a path and they can match multiple parts of it.
Use Cases
In the project I am currently working on we make a distinction between images and icons:
Since SVG imports are not recognized by TypeScript I want to create a global module declaration that targets all icon imports and another that targets all image imports. However, based on the feedback I got in this StackOverflow issue, it doesn't seem to be possible to do this since the support of wildcards in module paths seems to be very limited.
Examples
This is an example of what I would like to be able to do:
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: