Skip to content

if does not guard unkown not null correctlyΒ #44971

Closed
@JounQin

Description

@JounQin

Bug Report

πŸ”Ž Search Terms

if unkown null

πŸ•— Version & Regression Information

typescript@next

This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare const error: unknown

if (error) {
  throw typeof error === 'object' && 'message' in error ? Object.assign(new Error(), error) : error
}

πŸ™ Actual behavior

Object is possibly 'null'.

πŸ™‚ Expected behavior

No error, if (error) has already ensured error will never be null.

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