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
{{ message }}
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.
Did you search open and closed issues to see if your issue has already been reported?
Description
Ability to remap module names. In cases where other loaders are being used and TypeScripts moduleResolution is set to classic (and with TypeScript 2.0, where paths will be able to be supplied), there can be a disconnect between the module ID managed by typings and the location of the corresponding emitted code.
For example, if I have a ./node_modules/my-package/dist/amd/foo.js and a ./node_modules/my-package/dist/amd/foo.d.ts I would configure my package loader so that my-package/foo would resolve to node_modules/my-package/dist/amd/foo.js and therefore in my TypeScript code, I would want to import foo from 'my-package/foo'; to resolve to the typings in ./node_modules/my-package/dist/amd/foo.d.ts.
As far as I can tell though, typings will always create the "real" module as ~my-package/dist/amd/foo and alias the module to my-package/dist/amd/foo, neither of which will represent the run-time configuration.
I have read the documentation and open and closed tickets... While I found a couple things that sort of maybe would have helped, I have been unable to find a way of configuring a typings.json to be able to import a package and remap the module names.
As I mention above, in TypeScript 2.0 (which is unreleased as of this writing) there will be an ability to explicitly remap paths (see: Microsoft/TypeScript#5039) and this should allow TypeScript to resolve .ts files in other locations and sort of accomplish the above, but it would not provide the additional management of dependencies, etc. that typings/typings brings.
Currently we use dts-generator to general ambient/global definitions that are mapped, but then that of course causes other challenges of trying to manage ambient/global definitions.
Steps to Reproduce
Read lots of documentation
Mash lots of keys
Swear at laptop
Open an issue, wondering what I am missing
Expected behavior: [What did you expect to happen?]
Find a way to remap/alias/use a different root when using typings/typings.
Actual behavior: [What actually happened?]
Unable to find a way.
Versions
1.0.4
The text was updated successfully, but these errors were encountered:
There isn't currently any way to achieve this. I'd be open to a proposal, but I'm also hoping more of this would work at the TypeScript level. If TypeScript is remapping module paths, why wouldn't it automatically remap the global module paths to match?
For < TS 2.0, TypeScript does no remapping. We have used classic module resolution and expressed our typings as global typings, where the MID matches where the run-time location will be. We then keep the AMD loader configured to match that run-time location.
For example, if we had a module package/dist/umd/foo.js we would emit in our package.d.ts file:
And that would essentially allow TypeScript to resolve a reference to 'package/foo' to find a match in /node_modules/package/dist/umd/foo.d.ts based on the resolution logic.
I am not sure how TypeScript will be manifesting that in the TypeScript services, but even then it would only inform of a possible way of resolving the reference, versus actually giving a definitive name for a module.
So as far as a proposal, what would work for our use case (though I don't know if it would work for everyone) is to allow something like this in typings.json:
Prerequisites
0.x
to1.0
Description
Ability to remap module names. In cases where other loaders are being used and TypeScripts
moduleResolution
is set toclassic
(and with TypeScript 2.0, where paths will be able to be supplied), there can be a disconnect between the module ID managed by typings and the location of the corresponding emitted code.For example, if I have a
./node_modules/my-package/dist/amd/foo.js
and a./node_modules/my-package/dist/amd/foo.d.ts
I would configure my package loader so thatmy-package/foo
would resolve tonode_modules/my-package/dist/amd/foo.js
and therefore in my TypeScript code, I would want toimport foo from 'my-package/foo';
to resolve to the typings in./node_modules/my-package/dist/amd/foo.d.ts
.As far as I can tell though, typings will always create the "real" module as
~my-package/dist/amd/foo
and alias the module tomy-package/dist/amd/foo
, neither of which will represent the run-time configuration.I have read the documentation and open and closed tickets... While I found a couple things that sort of maybe would have helped, I have been unable to find a way of configuring a
typings.json
to be able to import a package and remap the module names.As I mention above, in TypeScript 2.0 (which is unreleased as of this writing) there will be an ability to explicitly remap paths (see: Microsoft/TypeScript#5039) and this should allow TypeScript to resolve
.ts
files in other locations and sort of accomplish the above, but it would not provide the additional management of dependencies, etc. that typings/typings brings.Currently we use dts-generator to general ambient/global definitions that are mapped, but then that of course causes other challenges of trying to manage ambient/global definitions.
Steps to Reproduce
Expected behavior: [What did you expect to happen?]
Find a way to remap/alias/use a different root when using typings/typings.
Actual behavior: [What actually happened?]
Unable to find a way.
Versions
1.0.4
The text was updated successfully, but these errors were encountered: