Closed
Description
TypeScript Version: 2.8.3
We have a base "abstract" (this is plain JS) class that defines an ExtensionAPI
which extensions need to extend to provide the implementation. Some of the methods (like startup
) are optional, and if not present, we can delay initializing the extensions on startup.
Typescript check complains that the base class doesn't have such methods, and the best solution I could figure out is to add a property to the ExtensionAPI.prototype
and properly @type
it, but that throws with error TS2425.
Code
class ExtensionAPI {
run(file) {
//
}
}
/** @type {function(string): void} */
ExtensionAPI.prototype.startup = null;
///
class Linter extends ExtensionAPI {
startup(file) {
//
}
run(file) {
//
}
}
///
/**
* @param {ExtensionAPI[]} extensions
*/
function init(extensions, file) {
for (let ext of extensions) {
if (ext.startup) {
ext.startup(file);
}
}
}
init([new Linter()], "Utitled1");
Typecheck using:
tsc --allowjs --checkjs --noemit extensions.js
Actual behavior:
error TS2425: Class 'ExtensionAPI' defines instance member property 'startup', but extended class 'Linter' defines it as instance member function.