⬅️ Back to Table of Contents
📄 truthinessUtils.ts
📊 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
isTruthyLiteral(type: ts.Type): boolean
Code
(type: ts.Type): boolean =>
tsutils.isTrueLiteralType(type) ||
(type.isLiteral() && !!getValueOfLiteralType(type))
- Parameters:
type: ts.Type
- Return Type:
boolean
isPossiblyFalsy(type: ts.Type): boolean
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))
- Parameters:
type: ts.Type
- Return Type:
boolean
- Calls:
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
isPossiblyTruthy(type: ts.Type): boolean
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)),
)
- Parameters:
type: ts.Type
- Return Type:
boolean
- Calls:
tsutils
.unionConstituents(type)
.map(type => tsutils.intersectionConstituents(type))
.some