TypeShadeError
On this page

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 26de7be8.

Syntax

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. 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

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

coderead only string

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

hintoptionalread only string

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

locoptionalread 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

Source

src/core/diagnostics/error.ts, line 63, at commit 26de7be8

Edit this page Report a problem