[API] Typekits
Typekits for working with array types(Model with number indexer).
/** * Create an array type. */$(program).array.create(elementType: Type): ArrayModelType;
getElementType
Section titled âgetElementTypeâ/** * Get the element type of an array. */$(program).array.getElementType(type: Model): Type;
/** * Check if a type is an array. */$(program).array.is(type: Entity): type is ArrayModelType;
builtin
Section titled âbuiltinâA kit of built-in types.
boolean
Section titled âbooleanâ/** * Accessor for the boolean builtin type. */$(program).builtin.boolean: Scalar;
/** * Accessor for the bytes builtin type, representing binary data. */$(program).builtin.bytes: Scalar;
decimal
Section titled âdecimalâ/** * Accessor for the decimal builtin type for high-precision decimal values. */$(program).builtin.decimal: Scalar;
decimal128
Section titled âdecimal128â/** * Accessor for the decimal128 builtin type, a 128-bit decimal value. */$(program).builtin.decimal128: Scalar;
duration
Section titled âdurationâ/** * Accessor for the duration builtin type, representing a span of time. */$(program).builtin.duration: Scalar;
/** * Accessor for the float builtin type, representing a double-precision floating-point number. */$(program).builtin.float: Scalar;
float32
Section titled âfloat32â/** * Accessor for the float32 builtin type, representing a single-precision floating-point number. */$(program).builtin.float32: Scalar;
float64
Section titled âfloat64â/** * Accessor for the float64 builtin type, representing a double-precision floating-point number. */$(program).builtin.float64: Scalar;
/** * Accessor for the int16 builtin type, representing a 16-bit signed integer. */$(program).builtin.int16: Scalar;
/** * Accessor for the int32 builtin type, representing a 32-bit signed integer. */$(program).builtin.int32: Scalar;
/** * Accessor for the int64 builtin type, representing a 64-bit signed integer. */$(program).builtin.int64: Scalar;
/** * Accessor for the int8 builtin type, representing an 8-bit signed integer. */$(program).builtin.int8: Scalar;
integer
Section titled âintegerâ/** * Accessor for the integer builtin type, representing an arbitrary-precision integer. */$(program).builtin.integer: Scalar;
numeric
Section titled ânumericâ/** * Accessor for the numeric builtin type, representing a numeric value. */$(program).builtin.numeric: Scalar;
offsetDateTime
Section titled âoffsetDateTimeâ/** * Accessor for the offsetDateTime builtin type, representing a date and time with an offset. */$(program).builtin.offsetDateTime: Scalar;
plainDate
Section titled âplainDateâ/** * Accessor for the plainDate builtin type, representing a date without time or offset. */$(program).builtin.plainDate: Scalar;
plainTime
Section titled âplainTimeâ/** * Accessor for the plainTime builtin type, representing a time without date or offset. */$(program).builtin.plainTime: Scalar;
safeInt
Section titled âsafeIntâ/** * Accessor for the safeInt builtin type, representing an integer within the safe range for JavaScript. */$(program).builtin.safeInt: Scalar;
/** * Accessor for the string builtin type. */$(program).builtin.string: Scalar;
/** * Accessor for the uint16 builtin type, representing a 16-bit unsigned integer. */$(program).builtin.uint16: Scalar;
/** * Accessor for the uint32 builtin type, representing a 32-bit unsigned integer. */$(program).builtin.uint32: Scalar;
/** * Accessor for the uint64 builtin type, representing a 64-bit unsigned integer. */$(program).builtin.uint64: Scalar;
/** * Accessor for the uint8 builtin type, representing an 8-bit unsigned integer. */$(program).builtin.uint8: Scalar;
/** * Accessor for the url builtin type, representing a valid URL string. */$(program).builtin.url: Scalar;
utcDateTime
Section titled âutcDateTimeâ/** * Accessor for the utcDateTime builtin type, representing a date and time in UTC. */$(program).builtin.utcDateTime: Scalar;
Typekits for working with the top level entity.
isAssignableTo Diagnosable
Section titled âisAssignableTo â/** * Check if the source type can be assigned to the target. * * @param source - Source type * * @param target - Target type * * @param diagnosticTarget - Target for the diagnostic */$(program).entity .isAssignableTo(source: Entity, target: Entity, diagnosticTarget?: Entity | Node): boolean;$(program).entity.isAssignableTo .withDiagnostics(source: Entity, target: Entity, diagnosticTarget?: Entity | Node): [boolean, readonly Diagnostic[]];
resolve Diagnosable
Section titled âresolve â/** * Resolve a type reference string to a TypeSpec type. By default any diagnostics are ignored. * * Call `resolve.withDiagnostics("Type")` to get a tuple containing the resolved type and any diagnostics. */$(program).entity.resolve(): reference: stringEntity | undefined;$(program).entity.resolve .withDiagnostics(): [reference: stringEntity | undefined, readonly Diagnostic[]];
A kit for working with enum types.
/** * Build an enum type. The enum type will be finished (i.e. decorators are run). */$(program).enum.create(desc: EnumDescriptor): Enum;
createFromUnion
Section titled âcreateFromUnionâ/** * Build an equivalent enum from the given union. * * @remarks * * Union variants which are not valid enum members are skipped. You can check if a union is a valid enum with {@link UnionKit.union}'s `isEnumValue`. * * Any API documentation will be rendered and preserved in the resulting enum. - No other decorators are copied from the union to the enum */$(program).enum.createFromUnion(type: Union): Enum;
/** * Check if `type` is an enum type. * * @param type - the type to check. */$(program).enum.is(type: Entity): type is Enum;
enumMember
Section titled âenumMemberâA kit for working with enum members.
/** * Create an enum member. The enum member will be finished (i.e. decorators are run). */$(program).enumMember.create(desc: EnumMemberDescriptor): EnumMember;
/** * Check if `type` is an enum member type. * * @param type - the type to check. */$(program).enumMember.is(type: Entity): type is EnumMember;
intrinsic
Section titled âintrinsicâ/** * The intrinsic 'any' type. */$(program).intrinsic.any: UnknownType;
/** * The intrinsic 'error' type. */$(program).intrinsic.error: ErrorType;
/** * Check if `entity` is an intrinsic type. * * @param entity - The `entity` to check. */$(program).intrinsic.is(entity: Entity): entity is IntrinsicType;
/** * The intrinsic 'never' type. */$(program).intrinsic.never: NeverType;
/** * The intrinsic 'null' type. */$(program).intrinsic.null: NullType;
/** * The intrinsic 'void' type. */$(program).intrinsic.void: VoidType;
literal
Section titled âliteralâA Typekit for working with literal types(string, numeric, boolean).
/** * Create a literal type from a JavaScript value. * * @param value - The JavaScript value to turn into a TypeSpec literal type. */$(program).literal .create(value: string | number | boolean): StringLiteral | NumericLiteral | BooleanLiteral;
createBoolean
Section titled âcreateBooleanâ/** * Create a boolean literal type from a JavaScript boolean value. * * @param value - The boolean value. */$(program).literal.createBoolean(value: boolean): BooleanLiteral;
createNumeric
Section titled âcreateNumericâ/** * Create a numeric literal type from a JavaScript number value. * * @param value - The numeric value. */$(program).literal.createNumeric(value: number): NumericLiteral;
createString
Section titled âcreateStringâ/** * Create a string literal type from a JavaScript string value. * * @param value - The string value. */$(program).literal.createString(value: string): StringLiteral;
/** * Check if `type` is a literal type. * * @param type - The type to check. */$(program).literal .is(type: Entity): type is StringLiteral | NumericLiteral | BooleanLiteral;
isBoolean
Section titled âisBooleanâ/** * Check if `type` is a boolean literal type. * * @param type - The type to check. */$(program).literal.isBoolean(type: Entity): type is BooleanLiteral;
isNumeric
Section titled âisNumericâ/** * Check if `type` is a numeric literal type. * * @param type - The type to check. */$(program).literal.isNumeric(type: Entity): type is NumericLiteral;
isString
Section titled âisStringâ/** * Check if `type` is a string literal type. * * @param type - The type to check. */$(program).literal.isString(type: Entity): type is StringLiteral;
Utilities for working with models.
/** * Create a model type. * * @param desc - The descriptor of the model. */$(program).model.create(desc: ModelDescriptor): Model;
getAdditionalPropertiesRecord
Section titled âgetAdditionalPropertiesRecordâ/** * Get the record representing additional properties, if there are additional properties. This method checks for additional properties in the following cases: 1. If the model is a Record type. 2. If the model extends a Record type. 3. If the model spreads a Record type. * * @param model - The model to get the additional properties type of. * * @returns The record representing additional properties, or undefined if there are none. */$(program).model.getAdditionalPropertiesRecord(model: Model): Model | undefined;
getDiscriminatedUnion Diagnosable
Section titled âgetDiscriminatedUnion â/** * Resolves a discriminated union for the given model from inheritance. * * @param type - Model to resolve the discriminated union for. */$(program).model .getDiscriminatedUnion(model: Model): DiscriminatedUnionLegacy | undefined;$(program).model.getDiscriminatedUnion .withDiagnostics(model: Model): [DiscriminatedUnionLegacy | undefined, readonly Diagnostic[]];
getEffectiveModel
Section titled âgetEffectiveModelâ/** * If the input is anonymous (or the provided filter removes properties) and there exists a named model with the same set of properties (ignoring filtered properties), then return that named model. Otherwise, return the input unchanged. * * This can be used by emitters to find a better name for a set of properties after filtering. For example, given `{ @metadata prop: string} & SomeName`, and an emitter that wishes to discard properties marked with `@metadata`, the emitter can use this to recover that the best name for the remaining properties is `SomeName`. * * @param model - The input model * * @param filter - An optional filter to apply to the input model's properties. */$(program).model.getEffectiveModel( model: Model, filter: (property: ModelProperty) => boolean): Model;
getProperties
Section titled âgetPropertiesâ/** * Gets all properties from a model, explicitly defined and implicitly defined. * * @param model - model to get the properties from */$(program).model.getProperties( model: Model, options: { includeExtended?: boolean; }): RekeyableMap<string, ModelProperty>;
/** * Check if the given `type` is a model.. * * @param type - The type to check. */$(program).model.is(type: Entity): type is Model;
isExpresion
Section titled âisExpresionâ/** * Check this is an anonyous model. Specifically, this checks if the model has a name. * * @param type - The model to check. */$(program).model.isExpresion(type: Model): boolean;
modelProperty
Section titled âmodelPropertyâUtilities for working with model properties.
For many reflection operations, the metadata being asked for may be found on the model property or the type of the model property. In such cases, these operations will return the metadata from the model property if it exists, or the type of the model property if it exists.
/** * Creates a modelProperty type. * * @param desc - The descriptor of the model property. */$(program).modelProperty.create(desc: ModelPropertyDescriptor): ModelProperty;
getEncoding
Section titled âgetEncodingâ/** * Get the encoding of the model property or its type. The property's type must be a scalar. * * @param property - The model property to get the encoding for. */$(program).modelProperty .getEncoding(property: ModelProperty): EncodeData | undefined;
getFormat
Section titled âgetFormatâ/** * Get the format of the model property or its type. The property's type must be a string. * * @param property - The model property to get the format for. */$(program).modelProperty.getFormat(property: ModelProperty): string | undefined;
getVisibilityForClass
Section titled âgetVisibilityForClassâ/** * Get the visibility of the model property. */$(program).modelProperty.getVisibilityForClass( property: ModelProperty, visibilityClass: Enum): Set<EnumMember>;
/** * Check if the given `type` is a model property. * * @param type - The type to check. */$(program).modelProperty.is(type: Entity): type is ModelProperty;
operation
Section titled âoperationâUtilities for working with operation properties.
/** * Create an operation type. * * @param desc - The descriptor of the operation. */$(program).operation.create(desc: OperationDescriptor): Operation;
getPagingMetadata Diagnosable
Section titled âgetPagingMetadata â/** * Get the paging operation's metadata for an operation. * * @param operation - operation to get the paging operation for */$(program).operation .getPagingMetadata(operation: Operation): PagingOperation | undefined;$(program).operation.getPagingMetadata .withDiagnostics(operation: Operation): [PagingOperation | undefined, readonly Diagnostic[]];
/** * Check if the type is an operation. * * @param type - type to check */$(program).operation.is(type: Entity): type is Operation;
RecordKit provides utilities for working with Record Model types.
/** * Create a Record Model type * * @param elementType - The type of the elements in the record */$(program).record.create(elementType: Type): RecordModelType;
getElementType
Section titled âgetElementTypeâ/** * Get the element type of a Record * * @param type - a Record Model type */$(program).record.getElementType(type: Model): Type;
/** * Check if the given `type` is a Record. * * @param type - The type to check. */$(program).record.is(type: Entity): type is RecordModelType;
Operations for scalar types like strings, numerics, booleans, dates, etc.
extendsBoolean
Section titled âextendsBooleanâ/** * Check if `type` extends the standard boolean type. * * @param type - The type to check. */$(program).scalar.extendsBoolean(type: Entity): type is Scalar;
extendsBytes
Section titled âextendsBytesâ/** * Check if `type` extends the standard bytes type. * * @param type - The type to check. */$(program).scalar.extendsBytes(type: Entity): type is Scalar;
extendsDecimal
Section titled âextendsDecimalâ/** * Check if `type` extends the standard decimal type. * * @param type - The type to check. */$(program).scalar.extendsDecimal(type: Entity): type is Scalar;
extendsDecimal128
Section titled âextendsDecimal128â/** * Check if `type` extends the standard decimal128 type. * * @param type - The type to check. */$(program).scalar.extendsDecimal128(type: Entity): type is Scalar;
extendsDuration
Section titled âextendsDurationâ/** * Check if `type` extends the standard duration type. * * @param type - The type to check. */$(program).scalar.extendsDuration(type: Entity): type is Scalar;
extendsFloat
Section titled âextendsFloatâ/** * Check if `type` extends the standard float type. * * @param type - The type to check. */$(program).scalar.extendsFloat(type: Entity): type is Scalar;
extendsFloat32
Section titled âextendsFloat32â/** * Check if `type` extends the standard float32 type. * * @param type - The type to check. */$(program).scalar.extendsFloat32(type: Entity): type is Scalar;
extendsFloat64
Section titled âextendsFloat64â/** * Check if `type` extends the standard float64 type. * * @param type - The type to check. */$(program).scalar.extendsFloat64(type: Entity): type is Scalar;
extendsInt16
Section titled âextendsInt16â/** * Check if `type` extends the standard int16 type. * * @param type - The type to check. */$(program).scalar.extendsInt16(type: Entity): type is Scalar;
extendsInt32
Section titled âextendsInt32â/** * Check if `type` extends the standard int32 type. * * @param type - The type to check. */$(program).scalar.extendsInt32(type: Entity): type is Scalar;
extendsInt64
Section titled âextendsInt64â/** * Check if `type` extends the standard int64 type. * * @param type - The type to check. */$(program).scalar.extendsInt64(type: Entity): type is Scalar;
extendsInt8
Section titled âextendsInt8â/** * Check if `type` extends the standard int8 type. * * @param type - The type to check. */$(program).scalar.extendsInt8(type: Entity): type is Scalar;
extendsInteger
Section titled âextendsIntegerâ/** * Check if `type` extends the standard integer type. * * @param type - The type to check. */$(program).scalar.extendsInteger(type: Entity): type is Scalar;
extendsNumeric
Section titled âextendsNumericâ/** * Check if `type` extends the standard numeric type. * * @param type - The type to check. */$(program).scalar.extendsNumeric(type: Entity): type is Scalar;
extendsOffsetDateTime
Section titled âextendsOffsetDateTimeâ/** * Check if `type` extends the standard offsetDateTime type. * * @param type - The type to check. */$(program).scalar.extendsOffsetDateTime(type: Entity): type is Scalar;
extendsPlainDate
Section titled âextendsPlainDateâ/** * Check if `type` extends the standard plainDate type. * * @param type - The type to check. */$(program).scalar.extendsPlainDate(type: Entity): type is Scalar;
extendsPlainTime
Section titled âextendsPlainTimeâ/** * Check if `type` extends the standard plainTime type. * * @param type - The type to check. */$(program).scalar.extendsPlainTime(type: Entity): type is Scalar;
extendsSafeint
Section titled âextendsSafeintâ/** * Check if `type` extends the standard safeint type. * * @param type - The type to check. */$(program).scalar.extendsSafeint(type: Entity): type is Scalar;
extendsString
Section titled âextendsStringâ/** * Check if `type` extends the standard string type. * * @param type - The type to check. */$(program).scalar.extendsString(type: Entity): type is Scalar;
extendsUint16
Section titled âextendsUint16â/** * Check if `type` extends the standard uint16 type. * * @param type - The type to check. */$(program).scalar.extendsUint16(type: Entity): type is Scalar;
extendsUint32
Section titled âextendsUint32â/** * Check if `type` extends the standard uint32 type. * * @param type - The type to check. */$(program).scalar.extendsUint32(type: Entity): type is Scalar;
extendsUint64
Section titled âextendsUint64â/** * Check if `type` extends the standard uint64 type. * * @param type - The type to check. */$(program).scalar.extendsUint64(type: Entity): type is Scalar;
extendsUint8
Section titled âextendsUint8â/** * Check if `type` extends the standard uint8 type. * * @param type - The type to check. */$(program).scalar.extendsUint8(type: Entity): type is Scalar;
extendsUrl
Section titled âextendsUrlâ/** * Check if `type` extends the standard url type. * * @param type - The type to check. */$(program).scalar.extendsUrl(type: Entity): type is Scalar;
extendsUtcDateTime
Section titled âextendsUtcDateTimeâ/** * Check if `type` extends the standard utcDateTime type. * * @param type - The type to check. */$(program).scalar.extendsUtcDateTime(type: Entity): type is Scalar;
getEncoding
Section titled âgetEncodingâ/** * Get the encoding information for a scalar type. Returns undefined if no encoding data is specified. * * Note: This will return the encoding data for the scalar type itself, not the model property that uses the scalar type. If this scalar might be referenced from a model property, use {@link modelProperty.getEncoding} instead. * * @param scalar - The scalar to get the encoding data for. */$(program).scalar.getEncoding(scalar: Scalar): EncodeData | undefined;
getFormat
Section titled âgetFormatâ/** * Get the well-known format for a string scalar. Returns undefined if no format is specified. * * Note: This will return the format data for the scalar type itself, not the model property that uses the scalar type. If this scalar might be referenced from a model property, use {@link ModelPropertyKit.getEncoding} instead. * * @param scalar - The scalar to get the format for. */$(program).scalar.getFormat(scalar: Scalar): string | undefined;
getStdBase
Section titled âgetStdBaseâ/** * Get the standard built-in base type of a scalar. For all built-in scalar types (numeric, string, int32, etc.) this will just return the scalar type. For user-defined scalars, this will return the first base scalar that is built-in. For user-defined scalars without a standard base type, this will return null. * * @param type - The scalar to check. */$(program).scalar.getStdBase(type: Scalar): Scalar | null;
/** * Check if `type` is any scalar type. * * @param type - The type to check. */$(program).scalar.is(type: Entity): type is Scalar;
isBoolean
Section titled âisBooleanâ/** * Check if `type` is exactly the standard boolean type. * * @param type - The type to check. */$(program).scalar.isBoolean(type: Entity): type is Scalar;
isBytes
Section titled âisBytesâ/** * Check if `type` is exactly the standard bytes type. * * @param type - The type to check. */$(program).scalar.isBytes(type: Entity): type is Scalar;
isDecimal
Section titled âisDecimalâ/** * Check if `type` is exactly the standard decimal type. * * @param type - The type to check. */$(program).scalar.isDecimal(type: Entity): type is Scalar;
isDecimal128
Section titled âisDecimal128â/** * Check if `type` is exactly the standard decimal128 type. * * @param type - The type to check. */$(program).scalar.isDecimal128(type: Entity): type is Scalar;
isDuration
Section titled âisDurationâ/** * Check if `type` is exactly the standard duration type. * * @param type - The type to check. */$(program).scalar.isDuration(type: Entity): type is Scalar;
isFloat
Section titled âisFloatâ/** * Check if `type` is exactly the standard float type. * * @param type - The type to check. */$(program).scalar.isFloat(type: Entity): type is Scalar;
isFloat32
Section titled âisFloat32â/** * Check if `type` is exactly the standard float32 type. * * @param type - The type to check. */$(program).scalar.isFloat32(type: Entity): type is Scalar;
isFloat64
Section titled âisFloat64â/** * Check if `type` is exactly the standard float64 type. * * @param type - The type to check. */$(program).scalar.isFloat64(type: Entity): type is Scalar;
isInt16
Section titled âisInt16â/** * Check if `type` is exactly the standard int16 type. * * @param type - The type to check. */$(program).scalar.isInt16(type: Entity): type is Scalar;
isInt32
Section titled âisInt32â/** * Check if `type` is exactly the standard int32 type. * * @param type - The type to check. */$(program).scalar.isInt32(type: Entity): type is Scalar;
isInt64
Section titled âisInt64â/** * Check if `type` is exactly the standard int64 type. * * @param type - The type to check. */$(program).scalar.isInt64(type: Entity): type is Scalar;
/** * Check if `type` is exactly the standard int8 type. * * @param type - The type to check. */$(program).scalar.isInt8(type: Entity): type is Scalar;
isInteger
Section titled âisIntegerâ/** * Check if `type` is exactly the standard integer type. * * @param type - The type to check. */$(program).scalar.isInteger(type: Entity): type is Scalar;
isNumeric
Section titled âisNumericâ/** * @param type - The type to check. */$(program).scalar.isNumeric(type: Entity): type is Scalar;
isOffsetDateTime
Section titled âisOffsetDateTimeâ/** * Check if `type` is exactly the standard offsetDateTime type. * * @param type - The type to check. */$(program).scalar.isOffsetDateTime(type: Entity): type is Scalar;
isPlainDate
Section titled âisPlainDateâ/** * Check if `type` is exactly the standard plainDate type. * * @param type - The type to check. */$(program).scalar.isPlainDate(type: Entity): type is Scalar;
isPlainTime
Section titled âisPlainTimeâ/** * Check if `type` is exactly the standard plainTime type. * * @param type - The type to check. */$(program).scalar.isPlainTime(type: Entity): type is Scalar;
isSafeint
Section titled âisSafeintâ/** * Check if `type` is exactly the standard safeint type. * * @param type - The type to check. */$(program).scalar.isSafeint(type: Entity): type is Scalar;
isString
Section titled âisStringâ/** * Check if `type` is exactly the standard string type. * * @param type - The type to check. */$(program).scalar.isString(type: Entity): type is Scalar;
isUint16
Section titled âisUint16â/** * Check if `type` is exactly the standard uint16 type. * * @param type - The type to check. */$(program).scalar.isUint16(type: Entity): type is Scalar;
isUint32
Section titled âisUint32â/** * Check if `type` is exactly the standard uint32 type. * * @param type - The type to check. */$(program).scalar.isUint32(type: Entity): type is Scalar;
isUint64
Section titled âisUint64â/** * Check if `type` is exactly the standard uint64 type. * * @param type - The type to check. */$(program).scalar.isUint64(type: Entity): type is Scalar;
isUint8
Section titled âisUint8â/** * Check if `type` is exactly the standard uint8 type. * * @param type - The type to check. */$(program).scalar.isUint8(type: Entity): type is Scalar;
/** * Check if `type` is exactly the standard url type. * * @param type - The type to check. */$(program).scalar.isUrl(type: Entity): type is Scalar;
isUtcDateTime
Section titled âisUtcDateTimeâ/** * Check if `type` is exactly the standard utcDateTime type. * * @param type - The type to check. */$(program).scalar.isUtcDateTime(type: Entity): type is Scalar;
/** * Creates a tuple type. * * @param values - The tuple values, if any. */$(program).tuple.create(values: Type[]): Tuple;
/** * Check if a type is a tuple. */$(program).tuple.is(type: Entity): type is Tuple;
/** * Clones a type and adds it to the typekit's realm. * * @param type - Type to clone */$(program).type.clone(type: T): T;
finishType
Section titled âfinishTypeâ/** * Finishes a type, applying all the decorators. */$(program).type.finishType(type: Type): void;
/** * Get the documentation of this type as specified by the `@doc` decorator or the JSDoc comment. * * @param type - The type to get the documentation for. */$(program).type.getDoc(type: Type): string | undefined;
getEncodedName
Section titled âgetEncodedNameâ/** * Get the name of this type in the specified encoding. */$(program).type.getEncodedName( type: Type & { name: string; }, encoding: string): string;
getPlausibleName
Section titled âgetPlausibleNameâ/** * Get the plausible name of a type. If the type has a name, it will use it otherwise it will try generate a name based on the context. If the type can't get a name, it will return an empty string. If the type is a TemplateInstance, it will prefix the name with the template arguments. * * @param type - The scalar to get the name of.z */$(program).type.getPlausibleName(type: Model | Union | Enum | Scalar): string;
getSummary
Section titled âgetSummaryâ/** * Get the summary of this type as specified by the `@summary` decorator. * * @param type - The type to get the summary for. */$(program).type.getSummary(type: Type): string | undefined;
inNamespace
Section titled âinNamespaceâ/** * Checks if the given type is in the given namespace (directly or indirectly) by walking up the type's namespace chain. * * @param type - The type to check. * * @param namespace - The namespace to check membership against. * * @returns True if the type is in the namespace, false otherwise. */$(program).type.inNamespace(type: Type, namespace: Namespace): boolean;
/** * Checks if `entity` is a Type. * * @param entity - The entity to check. */$(program).type.is(entity: Entity): entity is Type;
isAssignableTo Diagnosable
Section titled âisAssignableTo â/** * Check if the source type can be assigned to the target. * * @param source - Source type * * @param target - Target type * * @param diagnosticTarget - Target for the diagnostic */$(program).type .isAssignableTo(source: Type, target: Entity, diagnosticTarget?: Entity | Node): boolean;$(program).type.isAssignableTo .withDiagnostics(source: Type, target: Entity, diagnosticTarget?: Entity | Node): [boolean, readonly Diagnostic[]];
isError
Section titled âisErrorâ/** * Checks if a type is decorated with `@error` * * @param type - The type to check. */$(program).type.isError(type: Type): type is Model;
isNever
Section titled âisNeverâ/** * Checks if the given type is a never type. */$(program).type.isNever(type: Type): boolean;
isUserDefined
Section titled âisUserDefinedâ/** * Checks if the given type is a user defined type. Non-user defined types are defined in the compiler or other libraries imported by the spec. * * @param type - The type to check. * * @returns True if the type is a user defined type, false otherwise. */$(program).type.isUserDefined(type: Type): boolean;
maxItems
Section titled âmaxItemsâ/** * Gets the maximum number of items for an array type. * * @param type - type to get the maximum number of items for */$(program).type.maxItems(type: Type): number | undefined;
maxLength
Section titled âmaxLengthâ/** * Gets the maximum length for a string type. * * @param type - type to get the maximum length for */$(program).type.maxLength(type: Type): number | undefined;
maxValue
Section titled âmaxValueâ/** * Gets the maximum value for a numeric or model property type. * * @param type - type to get the maximum value for */$(program).type.maxValue(type: Type): number | undefined;
maxValueExclusive
Section titled âmaxValueExclusiveâ/** * Gets the maximum value this numeric type should be, exclusive of the given value. * * @param type - */$(program).type.maxValueExclusive(type: Type): number | undefined;
minItems
Section titled âminItemsâ/** * Gets the minimum number of items for an array type. * * @param type - type to get the minimum number of items for */$(program).type.minItems(type: Type): number | undefined;
minLength
Section titled âminLengthâ/** * Gets the minimum length for a string type. * * @param type - type to get the minimum length for */$(program).type.minLength(type: Type): number | undefined;
minValue
Section titled âminValueâ/** * Gets the minimum value for a numeric or model property type. * * @param type - type to get the minimum value for */$(program).type.minValue(type: Type): number | undefined;
minValueExclusive
Section titled âminValueExclusiveâ/** * Gets the minimum value this numeric type should be, exclusive of the given value. * * @param type - type to get the minimum value for */$(program).type.minValueExclusive(type: Type): number | undefined;
resolve Diagnosable
Section titled âresolve â/** * Resolve a type reference to a TypeSpec type. By default any diagnostics are ignored. * * If a `kind` is provided, it will check if the resolved type matches the expected kind and throw an error if it doesn't. * * Call `type.resolve.withDiagnostics("reference")` to get a tuple containing the resolved type and any diagnostics. */$(program).type .resolve(<K extends Type): ["kind"] | undefined>(reference: string, kind?: KK extends Type["kind"] ? Extract<Type, { kind: K; }> : undefined);$(program).type.resolve .withDiagnostics(<K extends Type): [["kind"] | undefined>(reference: string, kind?: KK extends Type["kind"] ? Extract<Type, { kind: K; }> : undefined), readonly Diagnostic[]];
Utilities for working with unions.
/** * Create an anonymous union type from an array of types. * * @param children - The types to create a union from. * * Any API documentation will be rendered and preserved in the resulting union. * * No other decorators are copied from the enum to the union. */$(program).union.create(children: Type[]): Union;
createFromEnum
Section titled âcreateFromEnumâ/** * Creates a union type from an enum. * * @remarks * * @param type - The enum to create a union from. * * For member without an explicit value, the member name is used as the value. * * Any API documentation will be rendered and preserved in the resulting union. * * No other decorators are copied from the enum to the union. */$(program).union.createFromEnum(type: Enum): Union;
/** * Creates a union type with filtered variants. * * @param filterFn - Function to filter the union variants */$(program).union.filter( union: Union, filterFn: (variant: UnionVariant) => boolean): Union;
getDiscriminatedUnion Diagnosable
Section titled âgetDiscriminatedUnion â/** * Resolves a discriminated union for the given union. * * @param type - Union to resolve the discriminated union for. */$(program).union .getDiscriminatedUnion(type: Union): DiscriminatedUnion | undefined;$(program).union.getDiscriminatedUnion .withDiagnostics(type: Union): [DiscriminatedUnion | undefined, readonly Diagnostic[]];
/** * Check if the given `type` is a union. * * @param type - The type to check. */$(program).union.is(type: Entity): type is Union;
isExpression
Section titled âisExpressionâ/** * Checks if an union is an expression (anonymous) or declared. * * @param type - Uniton to check if it is an expression */$(program).union.isExpression(type: Union): boolean;
isExtensible
Section titled âisExtensibleâ/** * Check if a union is extensible. Extensible unions are unions which contain a variant that is a supertype of all the other types. This means that the subtypes of the common supertype are known example values, but others may be present. * * @param type - The union to check. */$(program).union.isExtensible(type: Union): boolean;
isValidEnum
Section titled âisValidEnumâ/** * Check if the union is a valid enum. Specifically, this checks if the union has a name (since there are no enum expressions), and whether each of the variant types is a valid enum member value. * * @param type - The union to check. */$(program).union.isValidEnum(type: Union): boolean;
unionVariant
Section titled âunionVariantâUtilities for working with union variants.
Union variants are types that represent a single value within a union that can be one of several types.
/** * Create a union variant. * * @param desc - The descriptor of the union variant. */$(program).unionVariant.create(desc: UnionVariantDescriptor): UnionVariant;
/** * Check if the given `type` is a union. * * @param type - The type to check. */$(program).unionVariant.is(type: Entity): type is UnionVariant;
/** * Create a Value type from a JavaScript value. * * @param value - The JavaScript value to turn into a TypeSpec Value type. */$(program).value.create(value: string | number | boolean): Value;
createBoolean
Section titled âcreateBooleanâ/** * Create a boolean Value type from a JavaScript boolean value. * * @param value - The boolean value. */$(program).value.createBoolean(value: boolean): BooleanValue;
createNumeric
Section titled âcreateNumericâ/** * Create a numeric Value type from a JavaScript number value. * * @param value - The numeric value. */$(program).value.createNumeric(value: number): NumericValue;
createString
Section titled âcreateStringâ/** * Create a string Value type from a JavaScript string value. * * @param value - The string value. */$(program).value.createString(value: string): StringValue;
/** * Check if `type` is a Value type. * * @param type - The type to check. */$(program).value.is(type: Entity): type is Value;
isArray
Section titled âisArrayâ/** * Check if `type` is an array value type * * @param type - The type to check. */$(program).value.isArray(type: Entity): type is ArrayValue;
isAssignableTo Diagnosable
Section titled âisAssignableTo â/** * Check if the source type can be assigned to the target. * * @param source - Source type * * @param target - Target type * * @param diagnosticTarget - Target for the diagnostic */$(program).value .isAssignableTo(source: Value, target: Entity, diagnosticTarget?: Entity | Node): boolean;$(program).value.isAssignableTo .withDiagnostics(source: Value, target: Entity, diagnosticTarget?: Entity | Node): [boolean, readonly Diagnostic[]];
isBoolean
Section titled âisBooleanâ/** * Check if `type` is a boolean Value type. * * @param type - The type to check. */$(program).value.isBoolean(type: Entity): type is BooleanValue;
/** * Check if `type` is an enum value type * * @param type - The type to check. */$(program).value.isEnum(type: Entity): type is EnumValue;
/** * Check if `type` is a null value Type. * * @param type - The type to check. */$(program).value.isNull(type: Entity): type is NullValue;
isNumeric
Section titled âisNumericâ/** * Check if `type` is a numeric Value type. * * @param type - The type to check. */$(program).value.isNumeric(type: Entity): type is NumericValue;
isObject
Section titled âisObjectâ/** * Check if `type` is an object value type * * @param type - The type to check. */$(program).value.isObject(type: Entity): type is ObjectValue;
isScalar
Section titled âisScalarâ/** * Check if `type` is a scalar value type * * @param type - The type to check. */$(program).value.isScalar(type: Entity): type is ScalarValue;
isString
Section titled âisStringâ/** * Check if `type` is a string Value type. * * @param type - The type to check. */$(program).value.isString(type: Entity): type is StringValue;
resolve Diagnosable
Section titled âresolve â/** * Resolve a value reference to a TypeSpec value. By default any diagnostics are ignored. * * If a `kind` is provided, it will check if the resolved value matches the expected kind and throw an error if it doesn't. * * Call `value.resolve.withDiagnostics("reference")` to get a tuple containing the resolved value and any diagnostics. */$(program).value .resolve(<K extends Value): ["valueKind"] | undefined>(reference: string, kind?: KK extends Value["valueKind"] ? Extract<Value, { valueKind: K; }> : undefined);$(program).value.resolve .withDiagnostics(<K extends Value): [["valueKind"] | undefined>(reference: string, kind?: KK extends Value["valueKind"] ? Extract<Value, { valueKind: K; }> : undefined), readonly Diagnostic[]];