Closed
Description
Bug Report
Boolean output type
, Boolean() infer
🔎 Search Terms
Boolean infer
, Boolean condition
🕗 Version & Regression Information
Tested on latest version 4.6.2, but has the same behavior even back to 3.5.1.
Nightly version (4.7.0-dev.20220505) has the same behaviour.
⏯ Playground Link
Playground link with relevant code
💻 Code
const requiredArgFn = (value: string) => value
const optionalArgFn = (value?: string) => {
if (Boolean(value)) {
requiredArgFn(value) // Error: Type 'undefined' is not assignable to type 'string'.(2345)
}
if (!!value) {
requiredArgFn(value) // No error, type of value is 'string'
}
}
🙁 Actual behavior
Conditional checks with Boolean(value)
do not cause the value type to be non-nullable and non-false, as a double negation does (!!value
).
🙂 Expected behavior
Conditional checks with Boolean(value)
should cause the value type to be non-nullable and non-false, as a double negation does (!!value
).
Since the result of calling Boolean(someValue)
is always equal to the result of calling !!someValue
.