Closed
Description
TypeScript Version: 3.5.2
Search Terms: undefined, function arguments, variable, if condition, static code analysis
Code
const foo = (bar: number) => {};
const someOtherFunction = (bar?: number) => {
const shouldCallFoo = !!bar;
if (shouldCallFoo) {
foo(bar);
}
}
Expected behavior:
The code compiles without any problems
Actual behavior:
Error:
Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
Type 'undefined' is not assignable to type 'number'.
Related Issues: