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.

  1. const a: number = 6;
  2. switch (a) {
    case 0:
    Fallthrough case in switch.7029Fallthrough 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.

  1. function lookupHeadphonesManufacturer(color: "blue" | "black"): string {
    Function lacks ending return statement and return type does not include 'undefined'.2366Function lacks ending return statement and return type does not include 'undefined'.
    if (color === "blue") {
    return "beats";
    } else {
    "bose";
    }
    }
    Try
  • Default:

    false

  • Released:

    1.8

noPropertyAccessFromIndexSignature - noPropertyAccessFromIndexSignature

This setting ensures consistency between accessing a field via the “dot” (obj.key) syntax, and “indexed” (obj["key"]) and the way which the property is declared in the type.

Without this flag, TypeScript will allow you to use the dot syntax to access fields which are not defined:

  1. interface GameSettings {
    // Known up-front properties
    speed: "fast" | "medium" | "slow";
    quality: "high" | "low";
  2. // Assume anything unknown to the interface
    // is a string.
    [key: string]: string;
    }
  3. const settings = getSettings();
    settings.speed;
    // ^ = (property) GameSettings.speed: "fast" | "medium" | "slow"
  4. settings.quality;
    // ^ = (property) GameSettings.quality: "high" | "low"
  5. // Unknown key accessors are allowed on
    // this object, and are `string`
    settings.username;
    // ^ = string
    Try

Turning the flag on will raise an error because the unknown field uses dot syntax instead of indexed syntax.

  1. const settings = getSettings();
    settings.speed;
    settings.quality;
  2. // This would need to be settings["username"];
    settings.username;
    Property 'username' comes from an index signature, so it must be accessed with ['username'].4111Property 'username' comes from an index signature, so it must be accessed with ['username'].// ^ = string
    Try

The goal of this flag is to signal intent in your calling syntax about how certain you are this property exists.

  • Default:

    false

  • Released:

    4.2

noUncheckedIndexedAccess - noUncheckedIndexedAccess

TypeScript has a way to describe objects which have unknown keys but known values on an object, via index signatures.

  1. interface EnvironmentVars {
    NAME: string;
    OS: string;
  2. // Unknown properties are covered by this index signature.
    [propName: string]: string;
    }
  3. declare const env: EnvironmentVars;
  4. // Declared as existing
    const sysName = env.NAME;
    const os = env.OS;
    // ^ = const os: string
  5. // Not declared, but because of the index
    // signature, then it is considered a string
    const nodeEnv = env.NODE_ENV;
    // ^ = const nodeEnv: string
    Try

Turning on noUncheckedIndexedAccess will add undefined to any un-declared field in the type.

  1. declare const env: EnvironmentVars;
  2. // Declared as existing
    const sysName = env.NAME;
    const os = env.OS;
    // ^ = const os: string
  3. // Not declared, but because of the index
    // signature, then it is considered a string
    const nodeEnv = env.NODE_ENV;
    // ^ = const nodeEnv: string | undefined
    Try
  • Released:

    4.1

No Unused Locals - noUnusedLocals

Report errors on unused local variables.

  1. const createKeyboard = (modelID: number) => {
    const defaultModelID = 23;
    'defaultModelID' is declared but its value is never read.6133'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.

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

    false

  • Released:

    2.0