otris / jsdoc-tsd

JSDoc template for generating TypeScript definition files based on JSDoc comments.
MIT License
29 stars 7 forks source link

A 'declare' modifier cannot be used in an already ambient context #49

Closed whitlockjc closed 6 years ago

whitlockjc commented 6 years ago

As reported in https://github.com/whitlockjc/json-refs/issues/140, it seems like a declare in a module, namespace, ... causes the error thrown in the title. https://github.com/whitlockjc/json-refs/pull/143 shows how to fix this and has some details.

wehrstedt commented 6 years ago

Can you give me an example of the input, the output and what you expect it should look like?

whitlockjc commented 6 years ago

https://github.com/whitlockjc/json-refs is a perfect example. index.js and lib/typedefs.js end up creating the TypeScript definitions in index.d.ts. What happens is if you have a @typedef {object} that is a @memberof module:json-refs, when the interface is declared, it should not have a declare keyword. So declare interface JsonRefsOptions, it should just be interface JsonRefsOptions. _(Not sure if it should be export interface JsonRefsOptions, I'm new to TypeScript.

wehrstedt commented 6 years ago

Okay, I will have a look tomorrow

wehrstedt commented 6 years ago

I could easily reproduce this with the following jsdoc

/**
 * @module myModule
 */

/**
 * @interface myInterfaceInsideAModule
 * @memberof module:myModule
 */

which generates the following output

declare module 'myModule' {
    declare interface myInterfaceInsideAModule {
    }

}

The output should look like

declare module 'myModule' {
    interface myInterfaceInsideAModule {
    }

}

(the keyword "declare" is omitted for the interface)

wehrstedt commented 6 years ago

Good news: It can be fixed by just upgrading dts-dom

wehrstedt commented 6 years ago

@whitlockjc published v1.0.4. Can you verify it, please?

whitlockjc commented 6 years ago

v1.0.4 fixes my issues.