Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pragma disable for noUnusedLocals?

Tags:

typescript

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.

like image 905
Kenneth Brubaker Avatar asked Jul 07 '16 04:07

Kenneth Brubaker


1 Answers

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.

like image 99
Aluan Haddad Avatar answered Sep 18 '22 16:09

Aluan Haddad