Tree-shaking
Classes and/or methods in classes can be marked with @devsWhenUsed
JSDoc attribute.
This will cause them to be omitted from compilation unless they are used.
In such case, care needs to be taken when using index operator (obj[some_expression]
)
or accessing properties through any
type.
You can use ds.keep()
function to make sure methods are included.
/**
* Foooooo!
*
* @devsWhenUsed
*/
class Foo {
bar() {}
}
function callBar(v: any) {
v["bar"]()
}
callBar(new Foo())
// can be called anywhere from the reachable code
ds.keep(Foo.prototype.bar)
The @devsWhenUsed
attribute is implicit when methods are defined through
prototype assignments.
We may improve compiler warnings about such cases in future.
See discussion.