What causes the function foo to display an error message
Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'.
at the return value;
line while the function bar functions correctly?
function foo(value: string | number | null): string | null {
if (typeof value !== 'string' && value !== null) {
throw new Error();
}
return value;
}
function bar(value: string | number): string {
if (typeof value !== 'string') {
throw new Error();
}
return value;
}