Closed
Description
Bug Report
π Search Terms
typenarrowing, null
π Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about null and narrowing
β― Playground Link
Playground link with relevant code
π» Code
type A = {
c: null
d: string
} | {
c: string
d: null
} | {
c: string
d: string
}
const hello = (a: A): void => {
console.log(a.c)
console.log(a.d)
}
const main = (c: string | null, d: string | null): void => {
if (!c && !d) {
return;
}
if (!!c && !d) {
return hello ({c, d})
}
if (!c && !!d) {
return hello ({c, d})
}
return hello ({c, d})
}
π Actual behavior
Typescript doesn't narrow down the variables to be non-null at the end
π Expected behavior
Typescript should be able to narrow down the types to both be non-null