Skip to content

[I] Program

PropertyModifierTypeDescription
checkerpublicCheckerDANGER Using the checker is reserved for advanced usage and should be used with caution. API are not subject to the same stability guarantees see See https://typespec.io/docs/handbook/breaking-change-policy/
compilerOptionspublicCompilerOptions-
currentStagereadonlyCompilationStageThe current stage of the compilation pipeline. Progresses through: “parsing” → “checking” → “validating” → “linting” → “emitting”.
diagnosticsreadonlyreadonly Diagnostic[]-
emitterspublicEmitterRef[]-
hostpublicCompilerHost-
jsSourceFilespublicMap<string, JsSourceFileNode>-
projectRootreadonlystringProject root. If a tsconfig was found/specified this is the directory for the tsconfig.json. Otherwise directory where the entrypoint is located.
sourceFilespublicMap<string, TypeSpecScriptNode>All source files in the program, keyed by their file path.
tracerpublicTracer-
getGlobalNamespaceType(): Namespace;

Namespace


getSourceFileLocationContext(sourceFile): LocationContext;

Return location context of the given source file.

ParameterType
sourceFileSourceFile

LocationContext


hasError(): boolean;

boolean


reportDiagnostic(diagnostic): void;
ParameterType
diagnosticDiagnostic

void


reportDiagnostics(diagnostics): void;
ParameterType
diagnosticsreadonly Diagnostic[]

void


resolveTypeReference(reference): [Type | undefined, readonly Diagnostic[]];
ParameterType
referencestring

[Type | undefined, readonly Diagnostic[]]


stateMap(key): Map<Type, any>;
ParameterType
keysymbol

Map<Type, any>


stateSet(key): Set<Type>;
ParameterType
keysymbol

Set<Type>


trace(area, message): void;
ParameterType
areastring
messagestring

void


useCache<T>(
key,
type,
compute): T;

Get a cached value for the given key, computing it if not already cached. Caching is only active during the “validating” stage and later (not during “parsing” or “checking”) because decorators may mutate types during the checking stage, making cached values stale.

Type Parameter
T
ParameterTypeDescription
keysymbolA unique symbol identifying this cache entry.
typeTypeThe type to use as the cache key within this cache entry.
compute() => TA function that computes the value if not cached.

T

The cached or freshly computed value.