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;
function MyClass() {}
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;
declare function MyClass(): void;
declare class MyClass {
method(): void;
static staticMethod(): void; // <-- maybe it should be declared here?
}
declare namespace MyClass {
export { staticMethod, staticProperty, DoneCB };
}
declare var staticMethod: () => void; // <-- maybe it should be declared here?
declare var staticProperty: number;
/**
* Callback to be invoked when test execution is complete.
*/
type DoneCB = (failures: number) => any;
Actual behavior:
staticMethod is missing. (though it is included in the export {...}
statement.)
export = MyClass;
declare function MyClass(): void;
declare class MyClass {
method(): void;
}
declare namespace MyClass {
export { staticMethod, staticProperty, DoneCB };
}
declare var staticProperty: number;
/**
* Callback to be invoked when test execution is complete.
*/
type DoneCB = (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: