Skip to content

Commit

Permalink
feat: add isIntrinsicErrorType (#229)
Browse files Browse the repository at this point in the history
fix #226

<!-- 馃憢 Hi, thanks for sending a PR to ts-api-utils! 馃挅.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## 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`
  • Loading branch information
RebeccaStevens committed Jun 18, 2023
1 parent ef35c44 commit b623338
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/types/typeGuards/intrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit b623338

Please sign in to comment.