Skip to content

[I] Checker

Properties

PropertyModifierType
anyTypereadonlyUnknownType
errorTypereadonlyErrorType
neverTypereadonlyNeverType
nullTypereadonlyNullType
voidTypereadonlyVoidType

Methods

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


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


finishType()

finishType<T>(typeDef): T

Type Parameters

Type Parameter
T extends Type

Parameters

ParameterType
typeDefT

Returns

T


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

Using this API involves working with the TypeSpec Ast and may change at any time. See https://typespec.io/docs/handbook/breaking-change-policy/

Parameters

ParameterType
nodeNode

Returns

Type


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]