function toNumber(input: 'a' | 'b'): number {
switch (input) {
case 'a':
return 1;
case 'b':
return 2;
}
}
function bar(toNumber: (input: 'a' | 'b' | 'c') => number): number {
return toNumber('c');
}
bar(toNumber); // No typescript error, but returns `undefined`
I expect TypeScript to report an error the last line. There's clearly a type error there.
Is this a bug of the typescript compiler? If so, can you link me to an open issue in the compiler repo or should I create one?
Typescript only ignores this error when the option
strictis set tofalse.(Thanks @andy-ray for pointing that out in the comments)