-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeCommittedThe team has roadmapped this issueThe team has roadmapped this issueHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
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
yortus, Seikho, svieira, glen-84, HerringtonDarkholme and 1 moreyortus and HerringtonDarkholme
Metadata
Metadata
Assignees
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeCommittedThe team has roadmapped this issueThe team has roadmapped this issueHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript