📄 containsAllTypesByName¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 2 |
| 📦 Imports | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/type-utils/src/containsAllTypesByName.ts
📦 Imports¶
| Name | Source |
|---|---|
isTypeFlagSet |
./typeFlagUtils |
Functions¶
containsAllTypesByName(type: ts.Type, allowAny: boolean, allowedNames: Set<string>, matchAnyInstead: boolean): boolean¶
Parameters:
typeany: Type being checked by name.allowAnyany: Whether to consideranyandunknownto match.allowedNamesany: Symbol names checking on the type.matchAnyInsteadany: Whether to instead just check if any parts match, rather than all parts.
Returns: undefined
Whether the type is, extends, or contains the allowed names (or all matches the allowed names, if mustMatchAll is true).
Raw JSDoc
/**
* @param type Type being checked by name.
* @param allowAny Whether to consider `any` and `unknown` to match.
* @param allowedNames Symbol names checking on the type.
* @param matchAnyInstead Whether to instead just check if any parts match, rather than all parts.
* @returns Whether the type is, extends, or contains the allowed names (or all matches the allowed names, if mustMatchAll is true).
*/
Calls:
isTypeFlagSet (from ./typeFlagUtils)tsutils.isTypeReferencetype.getSymbolallowedNames.hascontainsAllTypesByNametsutils.isUnionOrIntersectionTypetype.types.sometype.types.everytype.getBaseTypesbases.somebases.every
Code
export function containsAllTypesByName(
type: ts.Type,
allowAny: boolean,
allowedNames: Set<string>,
matchAnyInstead = false,
): boolean {
if (isTypeFlagSet(type, ts.TypeFlags.Any | ts.TypeFlags.Unknown)) {
return !allowAny;
}
if (tsutils.isTypeReference(type)) {
type = type.target;
}
const symbol = type.getSymbol();
if (symbol && allowedNames.has(symbol.name)) {
return true;
}
const predicate = (t: ts.Type): boolean =>
containsAllTypesByName(t, allowAny, allowedNames, matchAnyInstead);
if (tsutils.isUnionOrIntersectionType(type)) {
return matchAnyInstead
? type.types.some(predicate)
: type.types.every(predicate);
}
const bases = type.getBaseTypes();
return (
bases != null &&
(matchAnyInstead
? bases.some(predicate)
: bases.length > 0 && bases.every(predicate))
);
}
Internal helpers¶
Declared inside another function in this file.
predicate(t: ts.Type): boolean¶
Parameters:
tts.Type
Returns: boolean
Calls:
containsAllTypesByName
Generated by Syntax Scribe