-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Output declarations should include module name #17379
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
Comments
module names will not be changed in the declaration output unless |
@mhegazy can you explain why custom module names should be discarded absent It seems to me that the output declaration file should exactly mirror the "shape" of the TypeScript source file. With the current behavior they don't quite match up. Even if emitting custom modules names is not the default, it would be great if it could be an option. |
how are you packaging these modules to your users? |
@mhegazy we are currently using NuGet packages on an internal NuGet feed. We want to migrate to NPM packages on an internal NPM feed, but we aren't there yet. Either way we need to custom module name to be preserved in transit because the consuming application will be referencing these modules as remotely-hosted AMD modules resolved and loaded via RequireJS at runtime. |
and |
I don't think outFile would work. We need the compiled JS to stay in separate files since we leverage the capability to load just the modules required by the page (as well as dynamically loading additional modules at runtime) |
so if the modules are left in their own files, i would recommend keeping the .d.ts in the same structure. the main difference between a |
As a consumer of an AMD module I would expect the import name and the file name to match unless explicitly documented otherwise. If they do not match then, unless you add additional configuration to your AMD loader then it will not be able to locate them. If you want to use a different module name than the file name you should consider using paths configuration in Also named defines should be avoided for the same reason that TypeScript avoids emitting |
@mhegazy @aluanhaddad thank you for your continued engagement here. A few thoughts:
|
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
In general, I understand your desire to abstract the module specifier used to import a module from the file name or URL. However, JavaScript module systems typically consider the file name to be the specifier (although additional resolution logic is added to at least some degree by all practical mechanisms). Aliasing, or abstracted module naming, via mechanisms such as import $ = require('jquery');
$('div').text('from $'); and have it resolve to
While I am not entirely sure what you mean by "throw away", as stated above, having /// <amd-module name="foo" />
export class Bar { ... } emit a declaration file declare module "foo" {
export class Bar { ... }
} pollutes the global namespace and therefore does not scale. This breaks one of the key use cases for aliasing, multi-versioning, something which TypeScript should have better support for, not worse. Mashups are a very good reason to avoid ambient declarations because two occurrences of This does create problems when exposing an API for consumption or when using package mangers or loaders that do not follow NodeJS conventions. Explicit |
@aluanhaddad it seems like the primary concern here is pollution of the global namespace. I see that, but I guess I would assert that people who are using custom module names are doing so in a way that avoids naming collisions (e. g. similar to how languages like C# use qualified names rather than file paths to avoid conflicts). In that sense, were we to care about multi-versioning we'd probably do so via different custom module names (although in our case we've never had this need). I agree that paths is the right current workaround (it's what we are using currently); I just wish it "just worked" instead. I'm curious whether you think other users of custom module names would want this behavior or whether they would prefer the current behavior. I don't know all the use-cases of custom module names, but I'd assume that those who are using them want to avoid thinking about file paths as much as possible. |
EDIT: It seems I am mistaken. Given how I maintain that this is a very poor practice. @madelson the problem with choosing your own custom module names is that third party code such as libraries needs to be able to be authored without knowledge of how you plan to resolve the conflict. Given // bar.ts
/// <amd-module name="foo" />
export class Bar { ... } generating the following would hurt portability // bar.js
define((require, exports) => exports.Bar = class Bar {}); // bar.d.ts
declare module "foo" {export class Bar {}} As opposed to // bar.js
define((require, exports) => exports.Bar = class Bar {}); // main.js
require.config({
"paths": {
"foo": "bar"
}
}); // tsconfig.json
{
"compilerOptions": {
"paths": {
"foo": ["bar"]
}
}
} I would prefer the latter as it keeps options open and keeps modules concerned with their functionality, as opposed to by which specifier they will be imported. If you are doing it for more than a handful of modules, you are already maintaining a lot of boilerplate in the triple-slash-comments in the first place. Also, it makes sense to put these settings at project level or package level. |
TypeScript Version: Microsoft.TypeScript.MSBuild 2.4.1
Code
Expected behavior:
I would expect my explicit module name to be preserved in the output .d.ts file:
Actual behavior:
The explictly-specified module name seems to be ignored completely:
The text was updated successfully, but these errors were encountered: