From 4f56bce577f49c65f10ebd9c808ee0fe277f06d9 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Sun, 18 Jun 2023 22:39:05 +1200 Subject: [PATCH] feat: add isIntrinsicErrorType fix #226 --- src/types/typeGuards/intrinsic.ts | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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. *