2

Why does this code fail to compile when using noImplicitReturns...

function foo(bar: "a"): number
{
    switch (bar)
    {
        case "a":
            return 1;
    }

    let unreachable;
}

error TS2366: Function lacks ending return statement and return type does not include 'undefined'.

...while this code compiles with not so much as a peep?

function foo(bar: "a"): number
{
    switch (bar)
    {
        case "a":
            return 1;
    }
}
Kendall Frey
  • 43,130
  • 20
  • 110
  • 148

0 Answers0