UNPKG

@typespec/http-server-js

Version:

TypeSpec HTTP server code generator for JavaScript

46 lines 2.47 kB
import { DiagnosticTarget, IntrinsicType, LiteralType, Namespace, NoTarget, Type } from "@typespec/compiler"; import { JsContext, Module } from "../ctx.js"; export type NamespacedType = Extract<Type, { namespace?: Namespace; }>; /** * Options for emitting a type reference. */ export interface EmitTypeReferenceOptions { /** * An optional alternative name to use for the type if it is not named. */ altName?: string; /** * Require a declaration for types that may be represented anonymously. */ requireDeclaration?: boolean; } /** * Emits a reference to a host type. * * This function will automatically ensure that the referenced type is included in the emit graph, and will import the * type into the current module if necessary. * * Optionally, a `preferredAlternativeName` may be supplied. This alternative name will be used if a declaration is * required, but the type is anonymous. The alternative name can only be set once. If two callers provide different * alternative names for the same anonymous type, the first one is used in all cases. If a declaration _is_ required, * and no alternative name is supplied (or has been supplied in a prior call to `emitTypeReference`), this function will * throw an error. Callers must be sure to provide an alternative name if the type _may_ have an unknown name. However, * callers may know that they have previously emitted a reference to the type and provided an alternative name in that * call, in which case the alternative name may be safely omitted. * * @param ctx - The emitter context. * @param type - The type to emit a reference to. * @param position - The syntactic position of the reference, for diagnostics. * @param module - The module that the reference is being emitted into. * @param preferredAlternativeName - An optional alternative name to use for the type if it is not named. * @returns a string containing a reference to the TypeScript type that represents the given TypeSpec type. */ export declare function emitTypeReference(ctx: JsContext, type: Type, position: DiagnosticTarget | typeof NoTarget, module: Module, options?: EmitTypeReferenceOptions): string; export declare function escapeUnsafeChars(s: string): string; export type JsTypeSpecLiteralType = LiteralType | (IntrinsicType & { name: "null"; }); export declare function isValueLiteralType(t: Type): t is JsTypeSpecLiteralType; //# sourceMappingURL=reference.d.ts.map