📄 truthinessUtils¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 3 |
| 📦 Imports | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/eslint-plugin/src/util/truthinessUtils.ts
📦 Imports¶
| Name | Source |
|---|---|
getValueOfLiteralType |
./getValueOfLiteralType |
Functions¶
isPossiblyFalsy(type: ts.Type): boolean¶
Parameters:
typets.Type
Returns: boolean
Calls:
tsutils .unionConstituents(type) // Intersections likestring & {}can also be possibly falsy, // requiring us to look into the intersection. .flatMap(type => tsutils.intersectionConstituents(type)) // PossiblyFalsy flag includes literal values, so exclude ones that // are definitely truthy .filter(t => !isTruthyLiteral(t)) .some
Code
(type: ts.Type): boolean =>
tsutils
.unionConstituents(type)
// Intersections like `string & {}` can also be possibly falsy,
// requiring us to look into the intersection.
.flatMap(type => tsutils.intersectionConstituents(type))
// PossiblyFalsy flag includes literal values, so exclude ones that
// are definitely truthy
.filter(t => !isTruthyLiteral(t))
.some(type => tsutils.isTypeFlagSet(type, ts.TypeFlags.PossiblyFalsy))
isPossiblyTruthy(type: ts.Type): boolean¶
Parameters:
typets.Type
Returns: boolean
Calls:
tsutils .unionConstituents(type) .map(type => tsutils.intersectionConstituents(type)) .some
Code
(type: ts.Type): boolean =>
tsutils
.unionConstituents(type)
.map(type => tsutils.intersectionConstituents(type))
.some(intersectionParts =>
// It is possible to define intersections that are always falsy,
// like `"" & { __brand: string }`.
intersectionParts.every(type => !tsutils.isFalsyType(type)),
)
isTruthyLiteral(type: ts.Type): boolean¶
Parameters:
typets.Type
Returns: boolean
Code
Generated by Syntax Scribe