---
title: "TypeShadeError: class in Diagnostics, TypeShade API"
description: "TypeShadeError, a class in Diagnostics. The error class this package throws."
url: https://typeshade.dev/api/typeshadeerror/
language: en
---

# `TypeShadeError`

Class in Diagnostics

The error class this package throws.

`import { TypeShadeError } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
class TypeShadeError extends Error
```

## Description

Every coded failure, whether an authoring-time type mismatch, a validation failure, or a feature a backend cannot emit, arrives as this class or a subclass of it, so `catch (e) { if (e instanceof TypeShadeError) … }` handles all of them.

Branch on [`TypeShadeError.code`](https://typeshade.dev/api/typeshadeerror/). The code is an `SD####` string from the append-only catalogue `CODES`; codes are never renumbered, so the code is the stable part of the error. `.message` combines the catalogue summary with the detail of this particular failure and may be reworded between releases.

`hint` is the catalogue’s one-line fix for the code, where it has one. `loc` points into the TypeScript that built the node (the file, line and column of the author’s own call), and is present only when source tracing was on at the time the node was built; turn it on with `setSourceTracing(true)` from `typeshade/dev`. Treat both fields as optional.

## Examples

### Example

```ts
import { TypeShadeError } from 'typeshade'

try {
  buildModule()
} catch (e) {
  if (e instanceof TypeShadeError && e.code === 'SD0002') {
    // binary op on mismatched vectors: report it against the author's own source
    console.error(e.message, e.loc)
  } else throw e
}
```

## Constructor

**`new TypeShadeError(opts: { code: string; message: string; hint?: string; loc?: SourceLoc })`**

## Instance properties

**`code` read only `string`**

The stable `SD####` catalogue code. Branch on this field.

**`hint` optional read only `string`**

The catalogue’s one-line fix, where the code has one. Absent otherwise.

**`loc` optional read only `SourceLoc`**

Where in the author’s TypeScript the offending node was built. Present only when source tracing was on at that time (`setSourceTracing(true)` from `typeshade/dev`), so treat it as optional.

## In the guide

- [Diagnostics](https://typeshade.dev/guide/internals/diagnostics/)

## Source

[`src/core/diagnostics/error.ts`, line 63](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/diagnostics/error.ts#L63), at commit af54ddad5
