Closed
Description
Bug Report
🔎 Search Terms
- if statement variable reassignment not assignable to parameter of type
- if statement variable reassignment not assignable
- if statement variable reassignment
- variable reassignment type
- variable reassignment
🕗 Version & Regression Information
- Relatively new to Typescript, encountered this on
typescript@4.2.4
⏯ Playground Link
Playground link with relevant code
💻 Code
function fooBar(foo: "bar" | "baz"): boolean {
return foo === "bar";
}
function fishTank(): boolean {
let input = "";
if (!input) {
input = "bar";
} else if (input !== "bar" && input !== "baz") {
return false;
}
return fooBar(input);
}
🙁 Actual behavior
Failed to compile, Argument of type 'string' is not assignable to parameter of type '"bar" | "baz"'.ts(2345)
🙂 Expected behavior
Compiles successfully.
Metadata
Metadata
Assignees
Labels
No labels