From b6233388814c54373d06bb362d800252a9eb23c8 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 19 Jun 2023 00:25:55 +1200 Subject: [PATCH] feat: add isIntrinsicErrorType (#229) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #226 ## PR Checklist - [x] Addresses an existing open issue: fixes #226 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/ts-api-utils/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/ts-api-utils/blob/main/.github/CONTRIBUTING.md) were taken ## Overview adds `isIntrinsicErrorType` --- 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. *