Type Generator
The type generator (@xriptjs/typegen) reads an xript manifest and produces TypeScript definition files (.d.ts). This gives extenders autocomplete, type checking, and inline documentation in their editors.
Installation
Section titled “Installation”npm install @xriptjs/typegenCLI Usage
Section titled “CLI Usage”# Print TypeScript definitions to stdoutxript-typegen manifest.json
# Write to a filexript-typegen manifest.json --output types.d.tsxript-typegen manifest.json -o types.d.tsExample
Section titled “Example”Given a manifest with a greet binding and a Position type:
$ xript-typegen manifest.jsonProduces:
// Auto-generated by @xriptjs/typegen// Source manifest: my-app v1.0.0// Do not edit manually.
/** A 2D position. */interface Position { /** Horizontal coordinate. */ x: number; /** Vertical coordinate. */ y: number;}
/** * Returns a greeting. * @param name - The name to greet. */declare function greet(name: string): string;Programmatic Usage
Section titled “Programmatic Usage”import { generateTypes, generateTypesFromFile } from "@xriptjs/typegen";
// From a manifest objectconst dts = generateTypes(manifest);
// From a fileconst { content } = await generateTypesFromFile("./manifest.json");Type Mapping
Section titled “Type Mapping”The generator maps manifest types to TypeScript following the rules in the Bindings spec:
| Manifest | TypeScript |
|---|---|
"string" | string |
"number" | number |
"boolean" | boolean |
"void" | void |
"string[]" | string[] |
{ "array": "Position" } | Position[] |
{ "union": ["string", "number"] } | string | number |
{ "map": "number" } | Record<string, number> |
{ "optional": "string" } | string | undefined |
Custom object types become interface declarations. Enum types become string literal unions (type Direction = "north" \| "south" \| ...).
Generated JSDoc
Section titled “Generated JSDoc”The generator includes JSDoc comments from manifest descriptions:
- Function descriptions become the main JSDoc comment
- Parameter descriptions become
@paramtags - Capability requirements become
@remarks Requires capability: \name“ annotations - Deprecation notices become
@deprecatedtags