Skip to content

Implicit type coersion of function to boolean in ternary operator #36921

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
kenrick95 opened this issue Feb 21, 2020 · 2 comments
Closed

Implicit type coersion of function to boolean in ternary operator #36921

kenrick95 opened this issue Feb 21, 2020 · 2 comments

Comments

@kenrick95
Copy link

TypeScript Version: 3.7.x-dev.20200220

Search Terms: Implicit type coersion function ternary

Code

function isSomething(): boolean {
  return false
}
const haha = isSomething ? 'a' : 'b';

Expected behavior: Typescript should throw error in = isSomething ? instead of coercing isSomething to boolean

Actual behavior: Typescript coerced isSomething (function) to boolean

Playground Link: link

Related Issues:

@IllusionMH
Copy link
Contributor

Fixed in #36402 (will be in 3.9)

@kenrick95
Copy link
Author

Omg thanks a lot @IllusionMH! Apologies for this duplicate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants