-
Notifications
You must be signed in to change notification settings - Fork 12
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
Generate "declare module" definition file #66
Comments
TsProject produces a single definition file for bundles. Definition files are built using the Typescript compiler API from the generated bundle source code, so are really dependent on the bundle source files.
Please let me know if this answers your question or not. |
No response from @heruan so I am closing this issue. |
@heruan I am reopening this issue. I now understand what you are asking for. I will try to get this into the 1.2.x NPM release. |
See issue #71 |
Thank you @ToddThomson! I was busy and couldn't give feedback, but that's what I meant 👍 |
My requirements for TsProject bundles are this:
For all 3 of these uses I want to have a clean bundle definition file with only the exports that define the public API. I also want to be able to minify ALL internal identifiers. I believe this can be achieved by convention and a bundle configuration property. For a commonjs node module I can make use of a Typescript namespace:
With the bundle configuration specifying the exportNamespace as TsProject the d.ts definition file will be constructed properly and all other exports will be considered internal giving the TsProject minifier a context to further minimize internal identifiers. |
If the bundle package is set to "library", TsProject will now wrap the the non-external module references in:
this will result in a d.ts file like
The "bundle name" is configured with "packageNamespace" in the bundle configuration. |
If the bundle package is set to "component", TsProject will only export the API in the namespace that matches the bundleNamespace configuration option. For TsProject itself ( a node application/component ), bundleNamespace is set to "TsProject" and package is set to "component". This results in the d.ts definition file:
|
@heruan This feature is now provided in the NPM release 1.2.0-rc.5. |
Thank you very much @ToddThomson! I'll try it out ASAP. |
@heruan You're welcome. Please use the latest rc.7 for testing. |
Feature(s) provided in TsProject 1.2. |
That's great, thank you! Is it also possibile to have TsProject generate just the bundles |
Also, I cannot get |
@heruan When I added this feature I originally provided "declare module". However, when I reviewed the feature with how Typescript 1.8.x defines a "module" it was apparent that "declare namespace" was the correct usage. |
@heruan I have complete control over the output stream and what file streams are output. To have only the bundle .d.ts definition file output I would need to add a bundle configuration option. Perhaps you could add an issue for this and I will add it to the 1.3 milestone. |
@ToddThomson I didn't know about {
"bundles": {
"my-module": {
"files": [ "..." ],
"config": {
"package": "module",
"declaration": true
}
}
}
} and use the declare module "my-module" {
// ...
} |
@heruan I'm going to reopen this issue for tracking purposes. I will review the use of declare "namespace" vs "module" again. However, I am almost certain that The namespace "name" comes from ts code, so you should be able to use whatever you like. |
@heruan OK, for ES6 modules, |
The TsProject packageNamespace bundle configuration option will be renamed to packageModuleName. TsProject will determine if the module name refers to a Typescript namespace ( "Internal" module ) or an ES6 module and output accordingly. |
That would be great! Why not use the keys of the |
@heruan I'll have some time early next week to resolve this issue. Whatever is simplest and works with all package types will be what I go with. Thanks again for your input. |
@heruan I've researched this issue and it is not straightforward in that there are a few TsProject concepts/features that are related. I want to find the simplest solution.
So, what I need to get from you is code ( a complete minimal TypeScript Project) that I can see that shows your need to have TsProject add an ambientDeclaration to the bundle d.ts file. My thoughts right now are that I can produce a bundle d.ts file directly with TypeScript 1.8 using: MyApp.ts - doesn't have to exist as a physical file for TsProject. TsProject could inject the simple code SourceFile.
in App.ts
MyAppConsumer.ts
The MyApp.d.ts produced is:
|
@heruan I'd like to release v1.2.2 this week if I can get this issue closed. Do you have some time early this week? |
Thank you @ToddThomson for your intereset. Here's a sample repository: https://github.com/heruan/tsproject-bundles export declare namespace foobar {
class Foo {
}
class Bar {
}
} where I would expect this: declare module "foobar" {
class Foo {
}
class Bar {
}
} |
@heruan Thank-you. Can you update your test project to include a "consumer" for your bundled library? I would like to see how the consumer would use the foobar.d.ts in the way that you have requested. |
@heruan There is so much conflicting information on how to structure a Typescript Declaration Module properly! From what I've read through concerning using Ambient Module Declarations ( what you are asking for - declare module "moduleName" {} ) within a d.ts is not the "current" / "proper" approach. |
Thank you @ToddThomson! The output you show here, i.e. declare namespace MyApp {
function src(): string;
}
declare module "MyApp" {
export = MyApp;
} could work for me, how can I get that? |
Is
tsproject
able to bundle TS definitions in a single.d.ts
file in the following form?It would be useful to bundle plugins and provide a single module-definition file.
The text was updated successfully, but these errors were encountered: