Closed
Description
Search Terms
Modules, import()
, Module Specifier, Module Namespace
Suggestion
Support inferring module specifier passed to type import function (import()
in type name space) to allow custom import function.
Use Cases
if I have a function that wraps require
, it's impossible to declare types for it:
function myRequire(moduleSpecifier) {
return require(moduleSpecifer);
}
Ideally I would like to declare types for a function like that as following:
declare function myRequire(moduleSpecifier: string): import(moduleSpecifier);
Use Cases
- Custom require functions are very common, specially for testing where they do mocking
- Jest mock functions can take advantage of this
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript / JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. new expression-level syntax)