Skip to content
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

declare as namespace externs without namespaced module output #905

Open
Feiyang1 opened this issue Oct 9, 2018 · 5 comments
Open

declare as namespace externs without namespaced module output #905

Feiyang1 opened this issue Oct 9, 2018 · 5 comments

Comments

@Feiyang1
Copy link

Feiyang1 commented Oct 9, 2018

I'm generating externs file from a d.ts file which defines an UMD module. In the output, the filename becomes the top level namespace. I want to generate externs without this top level namespace. Is it possible?

/**
 * @externs
 * @suppress {duplicate,checkTypes}
 */
// NOTE: generated by tsickle, do not edit.
// externs from :
/** @const */
var _$$index$d = {};
/** @const */
_$$index$d.A = {};

/**
 * @return {void}
 */
_$$index$d.A.hello = function() {};

the d.ts file:

declare namespace A {
    function hello(): void;
}

export = A;
export as namespace A;
@evmar
Copy link
Contributor

evmar commented Oct 9, 2018

We haven't yet figured out what it means to have externs from a module-shaped d.ts. I guess in your case because of the export as namespace, you want to generate some global A?

@Feiyang1
Copy link
Author

Feiyang1 commented Oct 9, 2018

Yep. I'd like to have

var A ={};
A.hello = function() {};

@evmar
Copy link
Contributor

evmar commented Oct 9, 2018

I think we don't have any support for this. If you'd like to hack it in for a one-time conversion, the code around

if (isExternalModule) {

is relevant.

@Feiyang1
Copy link
Author

thanks. Now I understand why it is doing this. I will probably just write a script to remove the export statements before feeding it into tsickle.

@evmar
Copy link
Contributor

evmar commented Oct 10, 2018

In TS, the export as namespace syntax means it appears both as a global and as a module, depending on some other factors that I forget right now. tsickle probably could use better support for d.ts files with that specific syntax but so far it doesn't know about it.

@evmar evmar changed the title generate externs without filename namespace for UMD modules declare as namespace externs without namespaced module output Oct 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants