Skip to content

[I] Checker

cloneType<T>(type, additionalProps?): T;
Type Parameter
T extends Type
ParameterType
typeT
additionalProps?{ [P in string | number | symbol]?: T[P] }

T


createAndFinishType<T>(typeDef): T & TypePrototype;
Type Parameter
T extends CreateTypeProps
ParameterType
typeDefT

T & TypePrototype


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

StringLiteral

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

NumericLiteral

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

BooleanLiteral

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

| BooleanLiteral | NumericLiteral | StringLiteral

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

| BooleanLiteral | NumericLiteral | StringLiteral


createType<T>(typeDef): T & TypePrototype & object;
Type Parameter
T extends CreateTypeProps
ParameterType
typeDefT

T & TypePrototype & object


finishType<T>(typeDef): T;
Type Parameter
T extends Type
ParameterType
typeDefT

T


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

Std type

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

StdTypes[T]


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/

ParameterType
nodeNode

Type


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”.

ParameterTypeDescription
valueValue

undefined | Type


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

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

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

type is Scalar & { name: IntrinsicScalarName }

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

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