You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dynamic imports using a simple template string could be matched against wildcard module declarations.
π Motivating Example
I am using the Rollup plugin dynamic-import-vars to handle import expressions with variable module names, for example to load image files as encoded strings:
constmodule=awaitimport(`./images/${name}.png`);
There is a wildcard declaration for these files in the project:
It would be great if the compiler tries to match such wildcard module declarations against template strings, maybe in a strict limited way such as:
only module declarations with a single leading or trailing asterisk
only against import expressions with a single template string containing leading/trailing matching characters (or string concatenation with matching string literals at beginning/end)
π» Use Cases
See example above. The workaround in this situation is to explicitly write a type assertion:
Another use case here would be to infer return type of functions based on a dynamic key specifying the file path to import from. Wicked for file based routing systems like remix.run
@suguanYang Right that issue sounds similar. While it is about using the type of a constant defined elsewhere in import expressions, this issue here is about the special case of wildcard module definitions and dynamic template strings.
Suggestion
π Search Terms
dynamic imports template string typed
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Dynamic imports using a simple template string could be matched against wildcard module declarations.
π Motivating Example
I am using the Rollup plugin dynamic-import-vars to handle import expressions with variable module names, for example to load image files as encoded strings:
There is a wildcard declaration for these files in the project:
It would be great if the compiler tries to match such wildcard module declarations against template strings, maybe in a strict limited way such as:
π» Use Cases
See example above. The workaround in this situation is to explicitly write a type assertion:
The text was updated successfully, but these errors were encountered: