Sonar version: Version 9.4 (build 54424)
TypeScript has a special syntax to declare the type of this
in a function by using it as the first parameter in the function declaration (reference).
In particular, this: void
can be used to prevent calls to this
in a function:
function doSomething(this: void) {
this.someProperty // will not compile
}
Code like the above will result in the following message (typescript:1172):
Remove the unused function parameter “this” or rename it to “_this” to make intention explicit.
This should not happen because:
- by using
this: void
it is made clear thatthis
will never be used - “this” is not a even a valid name for a function parameter in JavaScript and will cause a compilation error, so even in cases where
this
is not declared asvoid
the message is misleading.
Overall I think the this
parameter in TypeScript warrants special treatment.