Skip to content

static methods omitted from 'allowJs' 'declaration' .d.ts #36270

Description

TypeScript Version: Version 3.8.0-dev.20200117

Search Terms:

static method omitted
static method missing
allowJs function missing

Code

This is related to mochajs/mocha/issues/4154, where I'm experimenting with generating .d.ts from Mocha's JS source.

Input is JavaScript, with "allowJs" and "declaration" turned on.

module.exports=MyClass;functionMyClass(){}MyClass.staticMethod=function(){}MyClass.prototype.method=function(){}MyClass.staticProperty=123;/** * Callback to be invoked when test execution is complete. * * @callback DoneCB * @param {number} failures - Number of failures that occurred. */

Expected behavior:

With "allowJs" and "declaration" enabled, emits .d.ts that includes staticMethod. I'm not sure whether it should be included in the class body or with the other exports.

export=MyClass;declarefunctionMyClass(): void;declareclassMyClass{method(): void;staticstaticMethod(): void;// <-- maybe it should be declared here?}declarenamespaceMyClass{export{staticMethod,staticProperty,DoneCB};}declarevarstaticMethod: ()=>void;// <-- maybe it should be declared here?declarevarstaticProperty: number;/** * Callback to be invoked when test execution is complete. */typeDoneCB=(failures: number)=>any;

Actual behavior:

staticMethod is missing. (though it is included in the export {...} statement.)

export=MyClass;declarefunctionMyClass(): void;declareclassMyClass{method(): void;}declarenamespaceMyClass{export{staticMethod,staticProperty,DoneCB};}declarevarstaticProperty: number;/** * Callback to be invoked when test execution is complete. */typeDoneCB=(failures: number)=>any;

Playground Link:

I created a repl.it reproduction that calls the compiler, then prints the emitted d.ts.
https://repl.it/@AndrewBradley/missing-static-method

Related Issues:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesDomain: JavaScriptThe issue relates to JavaScript specificallyFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions