Options for converting NBT schemas to TypeScript interfaces.

interface NBTSchemaToTypeScriptInterfaceConversionOptions {
    allowExtraArrayItems?: boolean;
    allowExtraProps?: boolean;
    emitHelperTypes?: boolean;
    inlineRefs?: boolean;
    originalSymbolReference?: string | string[];
    refLookup?: Record<string, string | NBTSchema | NBTSchemaFragment>;
    schemaIDToSymbolNameResolver(schemaID: string): string;
}

Properties

allowExtraArrayItems?: boolean

Allows extra array items in lists.

This is currently bugged.

false
allowExtraProps?: boolean

Allows extra properties in compounds.

This is currently bugged.

false
emitHelperTypes?: boolean

Emit named type aliases for union branches.

This is currently bugged.

true
inlineRefs?: boolean

Whether to inline references to other NBT schemas.

false
originalSymbolReference?: string | string[]

The values to put in the @see TSDoc comment of the TypeScript interface.

refLookup?: Record<string, string | NBTSchema | NBTSchemaFragment>

Lookup for NBT schemas for the $ref property of NBT schemas.

nbtSchemas
writeFileSync(
path.join(import.meta.dirname, "./nbtSchemaTypeScriptTypes.d.ts"),
Object.entries(NBTSchemas.nbtSchemas)
.map(([name, schema]) =>
NBTSchemas.Utils.Conversion.ToTypeScriptType.nbtSchemaToTypeScriptType(schema, "DataTypes_" + name, {
originalSymbolReference: `NBTSchemas.nbtSchemas.${name}`, // This makes the generated types have a clickable link to go to the original NBT schema.
})
)
.join("\n\n")
);

Methods

  • Lookup for NBT schema TypeScript types from the $ref property of NBT schemas.

    Parameters

    • schemaID: string

      The ID of the NBT schema.

    Returns string

    The symbol name of the TypeScript interface.

    (schemaID: string) => schemaID