Skip to content

Add structured generic metadata support - #150

Draft
dacowan wants to merge 1 commit into
mainfrom
dacowan/1659586-typescript-generics-native-bindings
Draft

Add structured generic metadata support#150
dacowan wants to merge 1 commit into
mainfrom
dacowan/1659586-typescript-generics-native-bindings

Conversation

@dacowan

@dacowan dacowan commented Jul 26, 2026

Copy link
Copy Markdown

Summary

Adds structured generic type metadata to @minecraft/api-docs-generator and corresponding rendering support to @minecraft/markup-generators-plugin.

Metadata producers can now describe ordered generic declarations and recursive generic applications as data. The generators use that structure consistently across TypeScript declarations, MSDocs, cross-module links, and changelogs.

Why

The metadata model could describe concrete types but could not preserve relationships such as Container<T>, generic methods, nested applications, or generic inheritance without relying on pre-rendered TypeScript text.

Structured metadata is useful when the relationship can be represented directly: it remains machine-readable, participates in recursive type processing, and can be rendered consistently by every output format.

This does not replace the existing raw_script_text path. TypeScript-specific constructs such as conditional types, mapped types, indexed-access types, template-literal types, and complex type aliases remain better represented as TypeScript.

Metadata contract

The model adds:

interface MinecraftGenericTypeParameter {
    name: string;
    constraint?: MinecraftType;
    default?: MinecraftType;
}
  • generic_class_types on classes and interfaces
  • generic_function_types on functions and methods
  • generic_base and ordered generic_types on type records

Generic parameter and argument arrays preserve source order. All fields are optional, so existing non-generic metadata remains valid.

Generator behavior

  • Recursively processes generic bases, arguments, constraints, and defaults through existing type mapping and dependency resolution.
  • Renders generic classes, interfaces, functions, methods, properties, return types, arrays, optionals, and inheritance.
  • Preserves cross-module imports and MSDocs links for types nested inside generic applications.
  • Compares generic declarations and applications in changelogs while preserving semantic array order and ignoring dependency-version-only changes.
  • Emits one module-local structural NativeClass<T> helper when a valid reserved application is used, with validation for argument cardinality and public-name collisions.
  • Keeps existing non-generic interface and declaration behavior unchanged.

The producer-facing contract and ordering requirements are documented in tools/api-docs-generator/README.md.

Compatibility and scope

The new metadata fields are additive and optional. Existing non-generic fixtures and snapshots remain unchanged, and this PR does not modify production declaration output.

The structured model intentionally does not attempt to represent the complete TypeScript type system. Generic type-alias declarations, constructor type parameters, conditional and mapped types, variance, higher-kinded types, and raw TypeScript fragments remain outside its scope.

raw_script_text continues to work as before and does not trigger structured NativeClass<T> helper synthesis.

Validation

  • @minecraft/api-docs-generator: build, lint, and tests pass.
  • @minecraft/markup-generators-plugin: build, lint, and tests pass.
  • api-docs-generator-test-snapshots: build, lint, snapshots, and strict TypeScript diagnostics pass.
  • The end-to-end fixture covers ordered declarations, constraints, defaults, nested and cross-module applications, generic inheritance, MSDocs links, changelog changes, and NativeClass<T> synthesis.
  • npx beachball check recognizes both package change records.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@dacowan dacowan changed the title Task 1659586: Add structured generic metadata support Task AB#1659586: Add structured generic metadata support Jul 26, 2026
@dacowan dacowan changed the title Task AB#1659586: Add structured generic metadata support Add structured generic metadata support Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants