Skip to content

allow narrowing from any #9999

Closed
Closed

Description

There are numerous questions as to why any cannot be narrowed from. Despite being natural and intuitive this feature was rejected due to being a serious breaking change to poorly written yet massive code bases.

Please consider putting it behind a flag provided the evident need for it.

TLDR

  • any is not what you think it is (poor naming at play)
  • for narrowing use type unknown = {} | undefined | null | void instead
  • yes, it's a hot unfortunate mess
  • no, there is no painless way to fix it
  • yes, you gonna need to fix your *.d.ts by hands
  • why? to make average JS developers happy with their less than perfect code
  • welcome to the club! get your badge at the reception

UPDATE
@yortus made a branch per #9999 (comment) where narrowing from any works!

try it: npm install typescript-narrowany

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeWould introduce errors in existing codeCommittedThe team has roadmapped this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions