[I] Program
A compilation’s source files, semantic type graph, diagnostics, and library-owned state.
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
checker | public | Checker | DANGER 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/ |
compilerOptions | public | CompilerOptions | A shallow copy of the options supplied to this compilation; omitted options remain absent. |
diagnostics | readonly | readonly Diagnostic[] | Diagnostics reported so far, after suppression and warning-as-error handling. |
emitters | public | EmitterRef[] | Loaded emitters and their resolved options, in compilation emission order. |
host | public | CompilerHost | Host that supplies file-system access, module loading, and logging. |
jsSourceFiles | public | Map<string, JsSourceFileNode> | Loaded JavaScript modules, keyed by their file path. |
projectRoot | readonly | string | Directory of the resolved TypeSpec configuration file, or the entry point’s directory when no config is supplied. |
sourceFiles | public | Map<string, TypeSpecScriptNode> | All source files in the program, keyed by their file path. |
tracer | public | Tracer | Trace logger configured with this program’s trace filters. |
Methods
Section titled “Methods”getGlobalNamespaceType()
Section titled “getGlobalNamespaceType()”getGlobalNamespaceType(): Namespace;Get the unnamed root namespace containing this program’s top-level declarations.
Returns
Section titled “Returns”getSourceFileLocationContext()
Section titled “getSourceFileLocationContext()”getSourceFileLocationContext(sourceFile): LocationContext;Return location context of the given source file.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceFile | SourceFile |
Returns
Section titled “Returns”getTypeInfo()
Section titled “getTypeInfo()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
target | Type |
Returns
Section titled “Returns”TypeInfo | undefined
hasError()
Section titled “hasError()”hasError(): boolean;Whether an unsuppressed error has been reported, including promoted warnings.
Returns
Section titled “Returns”boolean
reportDiagnostic()
Section titled “reportDiagnostic()”reportDiagnostic(diagnostic): void;Add a diagnostic, applying suppression and the warning-as-error option.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
diagnostic | Diagnostic |
Returns
Section titled “Returns”void
reportDiagnostics()
Section titled “reportDiagnostics()”reportDiagnostics(diagnostics): void;Report each diagnostic using the same handling as reportDiagnostic.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
diagnostics | readonly Diagnostic[] |
Returns
Section titled “Returns”void
resolveTypeReference()
Section titled “resolveTypeReference()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
reference | string |
Returns
Section titled “Returns”[Type | undefined, readonly Diagnostic[]]
stateMap()
Section titled “stateMap()”stateMap(key): Map<Type, any>;Get the mutable, program-local map for a library’s state key, creating it if needed.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
key | symbol |
Returns
Section titled “Returns”Map<Type, any>
stateSet()
Section titled “stateSet()”stateSet(key): Set<Type>;Get the mutable, program-local set for a library’s state key, creating it if needed.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
key | symbol |
Returns
Section titled “Returns”Set<Type>
trace()
Section titled “trace()”trace(area, message): void;Log a trace message when the named area matches the configured trace filters.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
area | string |
message | string |
Returns
Section titled “Returns”void