TypeScript Version: 3.8.0-dev.20191119
Search Terms:
nullish
Code
const takesAString = (s: string) => s
let maybeString: string | null
const result = maybeString ?? takesAString(maybeString)
Expected behavior:
Since takesAString will never be executed when maybeString === null due to the nullish coalescing operator this code should be valid.
Actual behavior:
Passing maybeString to the function results in the error:
error TS2345: Argument of type 'string | null' is not assignable to parameter of type 'string'.
This only happens when strictNullChecks: true, but it should be fine either way.
Playground Link:
Playground link
Related Issues:
None