I've turned on noUnusedLocals
but I have a function that just checks for the existence of the first element but doesn't use it. Is there a pragma to turn this warning off for a code block?
Example:
export function has<T>(sequence: Iterable<T>): boolean {
for (let element of sequence) {
element; // Needed to quiet compiler setting `noUnusedLocals`.
return true;
}
return false;
}
The docs say to use _
:
Parameters declaration with names starting with _ are exempt from the unused parameter checking.
(See this)
But that only seems to apply for parameters, not local variables.
This is not really an answer in the strictest sense but _
as a name or name prefix suppresses --noUnusedLocals
in for..of
loop declarators in TypeScript 2.2.2 which is the current release at the time of this writing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With