Closed
Description
π Search Terms
"undefined is not assignable" assertion
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about common bugs
β― Playground Link
π» Code
interface Foo {
myvar: string;
}
interface Bar {
myvar?: string;
}
function handleFoo(_foo: Foo) {}
function handleBar(bar: Bar) {
if (!bar.myvar)
return;
handleFoo(bar);
}
π Actual behavior
Argument of type 'Bar' is not assignable to parameter of type 'Foo'.
Types of property 'myvar' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
π Expected behavior
It should work, as I verified myvar
is defined.
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
No labels