Skip to content

Conditional check with Boolean() transformation does not output type unlike double negation #48975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
torcoste opened this issue May 5, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@torcoste
Copy link

torcoste commented May 5, 2022

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.

@jcalz
Copy link
Contributor

jcalz commented May 5, 2022

another duplicate of #16655 (see #46952, #45601, #43546, #42572, etc)

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 5, 2022
@torcoste
Copy link
Author

torcoste commented May 6, 2022

another duplicate of #16655 (see #46952, #45601, #43546, #42572, etc)

Thanks, @jcalz!
I close issue then.

@torcoste torcoste closed this as completed May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants