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

support static members/methods in an interface #95

Merged

Conversation

aidinabedi
Copy link
Contributor

@aidinabedi aidinabedi commented Aug 29, 2019

JSDoc allows members (like functions and variables) to be static inside an interface (or mixin). Currently, this will generate invalid TypeScript. This PR fixes that by moving all static members to a namespace (which has the same name as the interface) and thus performs a namespace merge.

So the following JavaScript:

/**
 * @interface
 */
function Color() {}

/**
 * @function Color.staticMethod1
 * @static
 */
Color.staticMethod = function() {};

/**
 * @member {Number}
 * @static
 */
Color.staticMember = 1;

/**
 * @function
 */
Color.prototype.instanceMethod = function() {};

/**
 * @member {Number}
 */
Color.prototype.instanceMember = 2;

Will generate the following TypeScript:

declare namespace Color {
    /**
     * @function
     * @static
     */
    function staticMethod(): void;
    /**
     * @member {Number}
     * @static
     */
    var staticMember: number;
}

/**
 * @interface
 */
declare interface Color {
    /**
     * @function
     */
    instanceMethod(): void;
    /**
     * @member {Number}
     */
    instanceMember: number;
}

Which is perfectly valid TypeScript.

src/Emitter.ts Outdated Show resolved Hide resolved
…terface-children

# Conflicts:
#	test/fixtures/interface_all.js
@aidinabedi
Copy link
Contributor Author

Fixed conflicts.

@englercj englercj merged commit dec3b0d into englercj:master Sep 1, 2019
@aidinabedi aidinabedi deleted the feature/static-interface-children branch September 1, 2019 12:26
@aidinabedi aidinabedi mentioned this pull request Sep 1, 2019
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

Successfully merging this pull request may close these issues.

2 participants