TypeScript - (tsconfig) Linter Checks

#Linter Checks

A collection of extra checks, which somewhat cross the boundaries of compiler vs linter. You may prefer to use a tool like eslint over these options if you are looking for more in-depth rules.

# No Fallthrough Cases In Switch - noFallthroughCasesInSwitch
Report errors for fallthrough cases in switch statements. Ensures that any non-empty case inside a switch statement includes either break or return. This means you won’t accidentally ship a case fallthrough bug.

const a: number = 6;

switch (a) {
  case 0:
Fallthrough case in switch.
    console.log("even");
  case 1:
    console.log("odd");
    break;
}Try
Default:
false
Released:
1.8
# No Implicit Returns - noImplicitReturns
When enabled, TypeScript will check all code paths in a function to ensure they return a value.

function lookupHeadphonesManufacturer(color: "blue" | "black"): string {
Function lacks ending return statement and return type does not include 'undefined'.
  if (color === "blue") {
    return "beats";
  } else {
    "bose";
  }
}Try
Default:
false
Released:
1.8
# No Unused Locals - noUnusedLocals
Report errors on unused local variables.

const createKeyboard = (modelID: number) => {
  const defaultModelID = 23;
'defaultModelID' is declared but its value is never read.
  return { type: "keyboard", modelID };
};Try
Default:
false
Released:
2.0
# No Unused Parameters - noUnusedParameters
Report errors on unused parameters in functions.

const createDefaultKeyboard = (modelID: number) => {
'modelID' is declared but its value is never read.
  const defaultModelID = 23;
  return { type: "keyboard", modelID: defaultModelID };
};Try
Default:
false
Released:
2.0

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation