Search code examples
typescripttsconfig

Is it possible to force the typescript compiler check all possible branches when having a return type?


I see that the typescript checker does not give a warning or an error when having a function like this:

function test(a: boolean): boolean {
    if (a) {
        return true;
    } else {
        // else branch not covered
    }
}

Is there a property that could be set in the tsconfig.json file to force the compiler to do the check? (I could not find any)


Solution

  • The noImplicitReturns flag should do exactly that:

    https://www.typescriptlang.org/tsconfig#noImplicitReturns