📄 baseTypeUtils¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 5 |
| 📦 Imports | 5 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/eslint-plugin/src/util/baseTypeUtils.ts
📦 Imports¶
| Name | Source |
|---|---|
ParserServicesWithTypeInformation |
@typescript-eslint/utils |
InterfaceType |
typescript |
Type |
typescript |
isObjectFlagSet |
ts-api-utils |
isObjectType |
ts-api-utils |
Functions¶
hasBaseTypes(type: Type): type is InterfaceType¶
Parameters:
typeType
Returns: type is InterfaceType
Calls:
isObjectType (from ts-api-utils)isObjectFlagSet (from ts-api-utils)
Code
isNumberLike(type: Type): boolean¶
Parameters:
typeType
Returns: boolean
Calls:
tsutils .unionConstituents(type) .everytsutils .intersectionConstituents(unionPart) .sometsutils.isTypeFlagSet
Code
isStringLike(type: Type): boolean¶
Parameters:
typeType
Returns: boolean
Calls:
tsutils .unionConstituents(type) .everytsutils .intersectionConstituents(unionPart) .sometsutils.isTypeFlagSet
Code
matchesTypeOrBaseType(services: ParserServicesWithTypeInformation, matcher: (type: Type) => boolean, type: Type, seen: Set<Type>): boolean¶
Recursively checks if a type or any of its base types matches the provided matcher function.
Parameters:
servicesany: Parser services with type informationmatcherany: Function to test if a type matches the desired criteriatypeany: The type to checkseenany: Set of already visited types to prevent infinite recursion
Returns: undefined
true if the type or any of its base types match the matcher
Raw JSDoc
/**
* Recursively checks if a type or any of its base types matches the provided
* matcher function.
* @param services Parser services with type information
* @param matcher Function to test if a type matches the desired criteria
* @param type The type to check
* @param seen Set of already visited types to prevent infinite recursion
* @returns `true` if the type or any of its base types match the matcher
*/
Calls:
seen.hasseen.addmatcherservices.program.getTypeCheckergetBaseTypesForType(checker, type).somematchesTypeOrBaseType
Code
export function matchesTypeOrBaseType(
services: ParserServicesWithTypeInformation,
matcher: (type: Type) => boolean,
type: Type,
seen = new Set<Type>(),
): boolean {
if (seen.has(type)) {
return false;
}
seen.add(type);
if (matcher(type)) {
return true;
}
const checker = services.program.getTypeChecker();
return getBaseTypesForType(checker, type).some(base =>
matchesTypeOrBaseType(services, matcher, base, seen),
);
}
getBaseTypesForType(checker: ts.TypeChecker, type: ts.Type): readonly ts.Type[]¶
Parameters:
checkerts.TypeCheckertypets.Type
Returns: readonly ts.Type[]
Calls:
tsutils.isObjectTypetsutils.isTypeReferencetsutils.isObjectFlagSetchecker.getBaseTypes
Code
function getBaseTypesForType(
checker: ts.TypeChecker,
type: ts.Type,
): readonly ts.Type[] {
if (!tsutils.isObjectType(type)) {
return [];
}
const interfaceTarget = tsutils.isTypeReference(type) ? type.target : type;
const interfaceType =
tsutils.isObjectFlagSet(
interfaceTarget,
ts.ObjectFlags.Interface | ts.ObjectFlags.Class,
) && (interfaceTarget as ts.InterfaceType);
if (!interfaceType) {
return [];
}
return checker.getBaseTypes(interfaceType);
}
Generated by Syntax Scribe