noUnusedLocals and noUnusedParameters

With the noUnusedLocals and noUnusedParameters compiler options set, the TypeScript compiler will generate an error if it finds unused local variables, or unused parameters. Consider the following code:

function testFunction(input: string): boolean { 
    let test; 
    return false; 
} 

Here, we have defined a function, named testFunction, that takes a single parameter, named input, of type string. Within the body of the function, we define a variable named test, and then return the boolean value of false. Compiling this code will generate the following errors:

error TS6133: 'input' is declared but its value is never read
error TS6133: 'test' is declared but its value is never read

The first error is pointing to ...

Get Mastering TypeScript 3 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.