Skip to content

[I] Checker

Properties

PropertyModifierType
anyTypereadonlyUnknownType
errorTypereadonlyErrorType
neverTypereadonlyNeverType
nullTypereadonlyNullType
typePrototypepublicTypePrototype
voidTypereadonlyVoidType

Methods

checkProgram()

checkProgram(): void

Returns

void


checkSourceFile()

checkSourceFile(file): void

Parameters

ParameterType
fileTypeSpecScriptNode

Returns

void


cloneType()

cloneType<T>(type, additionalProps?): T

Type Parameters

Type Parameter
T extends Type

Parameters

ParameterType
typeT
additionalProps?{ [P in string | number | symbol]?: T[P] }

Returns

T


createAndFinishType()

createAndFinishType<T>(typeDef): T & TypePrototype

Type Parameters

Type Parameter
T extends CreateTypeProps

Parameters

ParameterType
typeDefT

Returns

T & TypePrototype


createFunctionType()

createFunctionType(fn): FunctionType

Parameters

ParameterType
fn(…args) => Type

Returns

FunctionType


createLiteralType()

Call Signature

createLiteralType(value, node?): StringLiteral
Parameters
ParameterType
valuestring
node?StringLiteralNode
Returns

StringLiteral

Call Signature

createLiteralType(value, node?): NumericLiteral
Parameters
ParameterType
valuenumber
node?NumericLiteralNode
Returns

NumericLiteral

Call Signature

createLiteralType(value, node?): BooleanLiteral
Parameters
ParameterType
valueboolean
node?BooleanLiteralNode
Returns

BooleanLiteral

Call Signature

createLiteralType(value, node?):
| BooleanLiteral
| NumericLiteral
| StringLiteral
Parameters
ParameterType
valuestring | number | boolean
node?| StringLiteralNode | NumericLiteralNode | BooleanLiteralNode
Returns

| BooleanLiteral | NumericLiteral | StringLiteral

Call Signature

createLiteralType(value, node?):
| BooleanLiteral
| NumericLiteral
| StringLiteral
Parameters
ParameterType
valuestring | number | boolean
node?| StringLiteralNode | NumericLiteralNode | BooleanLiteralNode
Returns

| BooleanLiteral | NumericLiteral | StringLiteral


createType()

createType<T>(typeDef): T & TypePrototype & object

Type Parameters

Type Parameter
T extends CreateTypeProps

Parameters

ParameterType
typeDefT

Returns

T & TypePrototype & object


evalProjection()

evalProjection(
node,
target,
args): Type

Parameters

ParameterType
nodeProjectionNode
targetType
argsType[]

Returns

Type


finishType()

finishType<T>(typeDef): T

Type Parameters

Type Parameter
T extends Type

Parameters

ParameterType
typeDefT

Returns

T


getGlobalNamespaceType()

getGlobalNamespaceType(): Namespace

Returns

Namespace


getLiteralType()

Call Signature

getLiteralType(node): StringLiteral
Parameters
ParameterType
nodeStringLiteralNode
Returns

StringLiteral

Call Signature

getLiteralType(node): NumericLiteral
Parameters
ParameterType
nodeNumericLiteralNode
Returns

NumericLiteral

Call Signature

getLiteralType(node): BooleanLiteral
Parameters
ParameterType
nodeBooleanLiteralNode
Returns

BooleanLiteral

Call Signature

getLiteralType(node): LiteralType
Parameters
ParameterType
nodeLiteralNode
Returns

LiteralType


getNamespaceString()

getNamespaceString(type, options?): string

Parameters

ParameterType
typeundefined | Namespace
options?TypeNameOptions

Returns

string

Deprecated

use import { getNamespaceFullName } from "@typespec/compiler";


getStdType()

getStdType<T>(name): StdTypes[T]

Std type

Type Parameters

Type Parameter
T extends | "Array" | IntrinsicScalarName | "Record"

Parameters

ParameterTypeDescription
nameTName

Returns

StdTypes[T]


getTypeForNode()

getTypeForNode(node): Type

Parameters

ParameterType
nodeNode

Returns

Type


getTypeName()

getTypeName(type, options?): string

Parameters

ParameterType
typeType
options?TypeNameOptions

Returns

string

Deprecated

use import { getTypeName } from "@typespec/compiler";


getValueExactType()

getValueExactType(value): undefined | Type

Return the exact type of a value.

const a: string = "hello";

calling getValueExactType on the value of a would give the string literal “hello”.

Parameters

ParameterTypeDescription
valueValue

Returns

undefined | Type


isStdType()

Call Signature

isStdType(type, stdType?): type is Scalar & { name: IntrinsicScalarName }

Check if the given type is one of the built-in standard TypeSpec Types.

Parameters
ParameterTypeDescription
typeScalarType to check
stdType?IntrinsicScalarNameIf provided check is that standard type
Returns

type is Scalar & { name: IntrinsicScalarName }

Call Signature

isStdType(type, stdType?): type is Type & { name: "Array" | IntrinsicScalarName | "Record" }
Parameters
ParameterType
typeType
stdType?| "Array" | IntrinsicScalarName | "Record"
Returns

type is Type & { name: “Array” | IntrinsicScalarName | “Record” }


isTypeAssignableTo()

isTypeAssignableTo(
source,
target,
diagnosticTarget): [boolean, readonly Diagnostic[]]

Check if the source type can be assigned to the target type.

Parameters

ParameterTypeDescription
sourceEntitySource type, should be assignable to the target.
targetEntityTarget type
diagnosticTargetDiagnosticTargetTarget for the diagnostic, unless something better can be inferred.

Returns

[boolean, readonly Diagnostic[]]

[related, list of diagnostics]


project()

project(
target,
projection,
args?): Type

Parameters

ParameterType
targetType
projectionProjectionNode
args?(string | number | boolean | Type)[]

Returns

Type


resolveCompletions()

resolveCompletions(node): Map<string, TypeSpecCompletionItem>

Parameters

ParameterType
nodeIdentifierNode

Returns

Map<string, TypeSpecCompletionItem>


resolveIdentifier()

resolveIdentifier(node): undefined | Sym

Parameters

ParameterType
nodeIdentifierNode

Returns

undefined | Sym


resolveTypeReference()

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

Check and resolve a type for the given type reference node.

Parameters

ParameterTypeDescription
nodeTypeReferenceNodeNode.

Returns

[undefined | Type, readonly Diagnostic[]]

Resolved type and diagnostics if there was an error.