Skip to content

[I] Program

A compilation’s source files, semantic type graph, diagnostics, and library-owned state.

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/
compilerOptionspublicCompilerOptionsA shallow copy of the options supplied to this compilation; omitted options remain absent.
diagnosticsreadonlyreadonly Diagnostic[]Diagnostics reported so far, after suppression and warning-as-error handling.
emitterspublicEmitterRef[]Loaded emitters and their resolved options, in compilation emission order.
hostpublicCompilerHostHost that supplies file-system access, module loading, and logging.
jsSourceFilespublicMap<string, JsSourceFileNode>Loaded JavaScript modules, keyed by their file path.
projectRootreadonlystringDirectory of the resolved TypeSpec configuration file, or the entry point’s directory when no config is supplied.
sourceFilespublicMap<string, TypeSpecScriptNode>All source files in the program, keyed by their file path.
tracerpublicTracerTrace logger configured with this program’s trace filters.
getGlobalNamespaceType(): Namespace;

Get the unnamed root namespace containing this program’s top-level declarations.

Namespace


getSourceFileLocationContext(sourceFile): LocationContext;

Return location context of the given source file.

ParameterType
sourceFileSourceFile

LocationContext


getTypeInfo(target): TypeInfo | undefined;

Query the registered $provideTypeInfo providers for extra information about the given type. Returns the merged information contributed by every library, or undefined when none contributed. Providers are run lazily and never mutate the type graph. Used by the language server for hover docs and by tooling.

Only libraries that opted into the experimental type-info-provider feature in their own tspconfig.yaml contribute; consumers do not need to enable anything.

ParameterType
targetType

TypeInfo | undefined


hasError(): boolean;

Whether an unsuppressed error has been reported, including promoted warnings.

boolean


reportDiagnostic(diagnostic): void;

Add a diagnostic, applying suppression and the warning-as-error option.

ParameterType
diagnosticDiagnostic

void


reportDiagnostics(diagnostics): void;

Report each diagnostic using the same handling as reportDiagnostic.

ParameterType
diagnosticsreadonly Diagnostic[]

void


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

Resolve a textual type reference in global scope, returning the type and any diagnostics. A failed resolution returns undefined; diagnostics are returned rather than reported.

ParameterType
referencestring

[Type | undefined, readonly Diagnostic[]]


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

Get the mutable, program-local map for a library’s state key, creating it if needed.

ParameterType
keysymbol

Map<Type, any>


stateSet(key): Set<Type>;

Get the mutable, program-local set for a library’s state key, creating it if needed.

ParameterType
keysymbol

Set<Type>


trace(area, message): void;

Log a trace message when the named area matches the configured trace filters.

ParameterType
areastring
messagestring

void