Add a @forceSuperCall tag in a method's JSDoc, and all overrides must call super or an error will be thrown during compilation.
npm install --save-dev ts-loader-forcesupertransformer
In your webpack config file, include the following code:
const forceSuperTransformer = require("ts-loader-forcesupertransformer");
module.exports = {
// ...
module: {
rules: [
{
test: /\.ts$/,
loader: "ts-loader",
options: {
getCustomTransformers: (program) => ({
before: [forceSuperTransformer(program)],
}),
},
},
],
},
};
To renew the transformer after every build, call the exported function with null
(necessary if using 'watch'):
module.exports = {
// ...
plugins: [
{
apply: (compiler) => {
compiler.hooks.done.tap("AfterBuildPlugin", (compilation) => {
forceSuperTransformer(null);
});
},
},
],
};
Add the following jsdoc tag
/**
*
* @forceSuperTransformer_forceSuperCall
*/
public fooBar():boolean
{
//important code
}
public override fooBar():boolean
{
super.fooBar(); // compilation error if missing
}
A custom JSDoc tag name can be provided:
const transformer = forceSuperTransformer(program, "customAttributeName");
If not provided, the name defaults to forceSuperTransformer_forceSuperCall
.
Not heavily tested. Contributions welcome.