Skip to content

Type assertions aren't merge rightΒ #45561

Closed
@leonovalex

Description

@leonovalex

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions