Skip to content

Type assertions aren't merge right #45561

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
leonovalex opened this issue Aug 24, 2021 · 1 comment
Closed

Type assertions aren't merge right #45561

leonovalex opened this issue Aug 24, 2021 · 1 comment

Comments

@leonovalex
Copy link

Bug Report

πŸ”Ž Search Terms

type assertions order

πŸ•— Version & Regression Information

Started at least from 3.3

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const receiver = (x: {}) => x;

const f = (x: unknown) => {
  if (typeof x !== 'object' || x == null) {
    return undefined
  }
  return receiver(x)
}

const f1 = (x: unknown) => {
  if (x == null || typeof x !== 'object') {
    return undefined
  }
  return receiver(x)
}

πŸ™ Actual behavior

Has error: Argument of type 'object | null' is not assignable to parameter of type '{}'. Type 'null' is not assignable to type '{}'.

πŸ™‚ Expected behavior

Shouldn't have any error. Checks are equivalent.

@MartinJohns
Copy link
Contributor

Duplicate of #28131. Used search terms: null typeof object

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