Skip to content
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

A problem with type checking in if statement. #31059

Closed
Arfey opened this issue Apr 22, 2019 · 2 comments · Fixed by #44730
Closed

A problem with type checking in if statement. #31059

Arfey opened this issue Apr 22, 2019 · 2 comments · Fixed by #44730
Labels
Duplicate An existing issue was already created

Comments

@Arfey
Copy link

Arfey commented Apr 22, 2019

TypeScript Version: 3.4.2

Search Terms:
A problem with type checking in if statement.

Code

{({ loading, data, error }) => {
    const canShow =
      !loading &&
      !error &&
      data &&
      data.recommendedPrice &&
      data.recommendedPrice.price;
    if (canShow) {
      return (
        <RecommendedPrice
          price={data.recommendedPrice.price}
          isActive={isActive}
        />
      );
    }

    return null;
}}

Expected behavior:
all is fine

Actual behavior:

object is possibly 'null'

But when i write something like that all is fine

{({ loading, data, error }) => {
    if (
      !loading &&
      !error &&
      data &&
      data.recommendedPrice &&
      data.recommendedPrice.price
    ) {
      return (
        <RecommendedPrice
          price={data.recommendedPrice.price}
          isActive={isActive}
        />
      );
    }

    return null;
}}
@ahejlsberg
Copy link
Member

Duplicate of #12184.

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Apr 22, 2019
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

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

Successfully merging a pull request may close this issue.

3 participants