Expose configuration hook for custom module resolution
See original GitHub issueFollowing on from #6012 and #5039, it’d be nice to have the ability to add TypeScript to projects with heterogeneous module resolution/packaging systems and have typechecking work.
The paths
and baseUrl
configuration options get us a long way, but they don’t deal well with module loaders that are less widely used, frequently changing, or that allow for complex module resolution rules. Letting the user entirely outsource all module resolution concerns using the configuration would allow type checking to work regardless of the user’s preference of npm, bower, requirejs, browserify, jspm, webpack, etc.
A simple approach might be to have a tsconfig
option for a parametrized command line invocation (similar to npm scripts) that is able to resolve modules. Each package manager can distribute a tool that implements module resolution according to its own needs, which the users can install and point to in their tsconfig.json
.
Exactly how extensive the API needs to be is up for debate. It could be something as simple as a function that maps requested module names to file system paths, or a more abstract implementation of something like System
from here, which could open up more interesting use cases (e.g. “virtual” modules built using code generation, or F# style type providers).
Issue Analytics
- State:
- Created 6 years ago
- Reactions:75
- Comments:21 (7 by maintainers)
Just saw this issue - I’d be quite interested as well to have such a hook. Would allow me to start making experiments to integrate PnP with Typescript 🙂
Year 2021, still looking forward on this.
This document https://www.typescriptlang.org/docs/handbook/module-resolution.html#module-resolution-strategies now is some complex, why not just give a hook function for user to do the resolve.