diff --git a/src/types/typeGuards/intrinsic.ts b/src/types/typeGuards/intrinsic.ts index 27c89f81..ad714aa2 100644 --- a/src/types/typeGuards/intrinsic.ts +++ b/src/types/typeGuards/intrinsic.ts @@ -84,6 +84,40 @@ export function isIntrinsicBigIntType( return isTypeFlagSet(type, ts.TypeFlags.BigInt); } +/** + * An "error" intrinsic type. + * + * This refers to a type generated when TypeScript encounters an error while + * trying to resolve the type. + * + * @category Type Types + */ +export interface IntrinsicErrorType extends IntrinsicType { + intrinsicName: "error"; +} + +/** + * Determines whether the given type is the "error" intrinsic type. + * + * The intrinsic error type occurs when TypeScript encounters an error while + * trying to resolve the type. + * + * @category Types - Type Guards + * @example + * ```ts + * declare const type: ts.Type; + * + * if (isIntrinsicErrorType(type)) { + * // ... + * } + * ``` + */ +export function isIntrinsicErrorType( + type: ts.Type +): type is IntrinsicErrorType { + return isIntrinsicType(type) && type.intrinsicName === "error"; +} + /** * A "symbol" intrinsic type. *