Closed
Description
Bug Report
🔎 Search Terms
typescript validation variable boolean failure
🕗 Version & Regression Information
Version 4.6.2 and below all seem to exhibit the same issue. Also confirmed most recent nightly build as of this filing exhibits the same issue.
This is the behavior in every version I tried, and I reviewed the FAQ for entries about TypeScript type validation
⏯ Playground Link
Playground link with relevant code
💻 Code
interface test {
val1: string | undefined;
}
function test1(input: string) {
console.log(input);
}
function test2(input: test) {
const canWork = input.val1 !== undefined;
// Fails
if (canWork) {
test1(input.val1);
}
// Succeeds
if (input.val1 !== undefined) {
test1(input.val1);
}
}
🙁 Actual behavior
Receive the following error for type validation:
Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.(2345)
🙂 Expected behavior
Type validation from the boolean expression should work.