TypeShadeError
클래스, 진단 분류
The error class this package throws.
import { TypeShadeError } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
class TypeShadeError extends Error설명
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.
예제
예제
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}생성자
new TypeShadeError(opts: { code: string; message: string; hint?: string; loc?: SourceLoc })
인스턴스 속성
code읽기 전용stringThe stable
SD####catalogue code. Branch on this field.hint선택 사항읽기 전용stringThe catalogue’s one-line fix, where the code has one. Absent otherwise.
loc선택 사항읽기 전용SourceLocWhere in the author’s TypeScript the offending node was built. Present only when source tracing was on at that time (
setSourceTracing(true)fromtypeshade/dev), so treat it as optional.
관련 가이드
소스
src/core/diagnostics/error.ts, 63행, 커밋 c66579bf 기준