Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(eslint-plugin): [no-unnecessary-condition] false positives with branded types#7466
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -28,13 +28,23 @@ const isTruthyLiteral = (type: ts.Type): boolean => | ||
| const isPossiblyFalsy = (type: ts.Type): boolean => | ||
| tsutils | ||
| .unionTypeParts(type) | ||
| // Intersections like `string & {}` can also be possibly falsy, | ||
| // requiring us to look into the intersection. | ||
| .flatMap(type => tsutils.intersectionTypeParts(type)) | ||
Comment on lines +31 to +33 ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This works because:
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. [External] Heh, I wonder if | ||
| // PossiblyFalsy flag includes literal values, so exclude ones that | ||
| // are definitely truthy | ||
| .filter(t => !isTruthyLiteral(t)) | ||
| .some(type => isTypeFlagSet(type, ts.TypeFlags.PossiblyFalsy)); | ||
| const isPossiblyTruthy = (type: ts.Type): boolean => | ||
| tsutils | ||
| .unionTypeParts(type) | ||
| .map(type => tsutils.intersectionTypeParts(type)) | ||
| .some(intersectionParts => | ||
| // It is possible to define intersections that are always falsy, | ||
| // like `"" & { __brand: string }`. | ||
| intersectionParts.every(type => !tsutils.isFalsyType(type)), | ||
| ); | ||
| // Nullish utilities | ||
| const nullishFlag = ts.TypeFlags.Undefined | ts.TypeFlags.Null; | ||