Skip to content

Critical: user-supplied code TEMPLATE for emitted ADTs (readonly, null/undefined, comments, serde) #51

Description

@MelbourneDeveloper

Problem

The language emitters (--to typescript, and presumably the others) hardcode the shape of generated ADTs. There is no way to control:

  • readonly vs mutable fields
  • null vs undefined for Option<T>
  • doc-comment passthrough from the .td source
  • (de)serialization helpers — e.g. fromJson / toJson, including wire-key casing (snake_case <-> camelCase)

Every codebase has its own conventions, so a fixed emitter cannot fit them. See the companion bug in this repo for the concrete TypeScript pain.

Proposed feature

A user-supplied code template per output target that controls how each ADT construct (type, union, alias, and each field) is rendered. Concretely, either:

  • a template file (Handlebars / EJS / Mustache) referenced via --template ts.tmpl, with access to the parsed model (names, fields, types, optionality, docs); or
  • render hooks in the Node API (typediagram-core) that let callers override per-node emission.

This would let a project emit, in one pass, e.g. readonly field: T | null with doc comments AND a generated parseX(raw): X deserializer — no post-processing.

Why critical

Without it, real adopters must regex-rewrite the emitter output and hand-maintain serde — exactly the fragility a codegen tool is supposed to remove. This is currently blocking clean adoption.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CRITICALCritical severity — fix immediatelyjavascriptPull requests that update javascript code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions