📄 needsToBeAwaited.ts¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 1 |
| 📦 Imports | 3 |
| 🎯 Enums | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/eslint-plugin/src/util/needsToBeAwaited.ts
📦 Imports¶
| Name | Source |
|---|---|
isTypeAnyType |
@typescript-eslint/type-utils |
isTypeUnknownType |
@typescript-eslint/type-utils |
getConstraintInfo |
./getConstraintInfo |
Functions¶
needsToBeAwaited(checker: ts.TypeChecker, node: ts.Node, type: ts.Type): Awaitable¶
Code
export function needsToBeAwaited(
checker: ts.TypeChecker,
node: ts.Node,
type: ts.Type,
): Awaitable {
const { constraintType, isTypeParameter } = getConstraintInfo(checker, type);
// unconstrained generic types should be treated as unknown
if (isTypeParameter && constraintType == null) {
return Awaitable.May;
}
// `any` and `unknown` types may need to be awaited
if (isTypeAnyType(constraintType) || isTypeUnknownType(constraintType)) {
return Awaitable.May;
}
// 'thenable' values should always be be awaited
if (tsutils.isThenableType(checker, node, constraintType)) {
return Awaitable.Always;
}
// anything else should not be awaited
return Awaitable.Never;
}
- Parameters:
checker: ts.TypeCheckernode: ts.Nodetype: ts.Type- Return Type:
Awaitable - Calls:
getConstraintInfo (from ./getConstraintInfo)isTypeAnyType (from @typescript-eslint/type-utils)isTypeUnknownType (from @typescript-eslint/type-utils)tsutils.isThenableType- Internal Comments:
Enums¶
enum Awaitable¶
Members¶
| Name | Value | Description |
|---|---|---|
Always |
auto | |
Never |
auto | |
May |
auto |