Flag unused declarations with —noUnusedParameters and —noUnusedLocals
TypeScript 2.0 has two new flags to help you maintain a clean code base.—noUnusedParameters
flags any unused function or method parameters errors.—noUnusedLocals
flags any unused local (un-exported) declaration like variables, functions, classes, imports, etc…Also, unused private members of a class would be flagged as errors under —noUnusedLocals
.
Example
import B, { readFile } from "./b";
// ^ Error: `B` declared but never used
readFile();
export function write(message: string, args: string[]) {
// ^^^^ Error: 'arg' declared but never used.
console.log(message);
}
Parameters declaration with names starting with _
are exempt from the unused parameter checking.e.g.:
function returnNull(_a) { // OK
return null;
}