Skip to content

Add MergeLeafTypes helper and export leaf types#210

Merged
Eyas merged 3 commits intogoogle:mainfrom
cochinescu:merge-leaf-types
Mar 23, 2026
Merged

Add MergeLeafTypes helper and export leaf types#210
Eyas merged 3 commits intogoogle:mainfrom
cochinescu:merge-leaf-types

Conversation

@cochinescu
Copy link
Copy Markdown
Contributor

@cochinescu cochinescu commented Mar 21, 2026

Summary

  • export generated leaf types so concrete schema leaves can be referenced publicly
  • move MergeLeafTypes<> and its internal helper machinery into schema-dts-lib
  • have generated schema output import/export MergeLeafTypes from schema-dts-lib
  • add consumer compile coverage and update docs

Notes

  • this is intentionally additive: existing exported union aliases like Thing and Product are unchanged
  • the leaf export change applies to both the standard class leaf declarations and the separate RoleBuiltin leaf type-alias path
  • WithContext, Graph, and SchemaValue remain in generator helper output; MergeLeafTypes<> lives in schema-dts-lib with the other schema-agnostic helpers
  • most of the diff is expected generator snapshot churn from the new import/export stanza plus public *Leaf declarations

Verification

  • NODE_OPTIONS=--experimental-vm-modules ./node_modules/.bin/jest packages/schema-dts-gen/test --runInBand -u
  • ./node_modules/.bin/tsc -b packages/schema-dts-lib
  • ./node_modules/.bin/tsc -b packages/schema-dts-gen/src
  • node packages/schema-dts-gen/dist/src/cli/cli.js > packages/schema-dts/lib/schema.ts
  • ./node_modules/.bin/tsc -p packages/schema-dts
  • ./node_modules/.bin/tsc -p packages/schema-dts/test
  • npm run fix:prettier

Fixes #203

@Eyas
Copy link
Copy Markdown
Collaborator

Eyas commented Mar 21, 2026

Random thought (let me know if this is too much of a hassle and I can do part of the change and have you rebase on top of it): I wonder if we can separate the utility types into their own package (e.g. schema-dts-helpers @schema-dts/helpers or similar) and then have the emitted code start with:

import type { WithContext, Graph, MergeLeafTypes } from "schema-dts-helpers";
export {WithContext, Graph, MergeLeafTypes};

instead of the long stanza in each file.

It'll make the snapshot tests & churn easier to read, and it means that we can write things the way we want instead of relying on imperatively constructing the AST with codegen.

Let me know if you'd like me to make the initial structure for that.

@Eyas
Copy link
Copy Markdown
Collaborator

Eyas commented Mar 21, 2026

top-level npm test is currently blocked by an unrelated existing lint error in packages/schema-dts/test/withactionconstraints.ts

That's not actually an error, but a problem with the testing -- looks like you need to actively rerun npm run build (of schema-dts-gen at least) before the schema-dts tests work properly.

@cochinescu
Copy link
Copy Markdown
Contributor Author

Thanks, this makes sense.

I’m happy to rework the PR in that direction. If you want to sketch the initial helper-package structure, I can rebase on top of it; otherwise I can take a first pass at wiring it up here.

Also thanks for the note on testing — I’ll rerun the schema-dts tests with the required build step and update the PR description accordingly.

@cochinescu
Copy link
Copy Markdown
Contributor Author

Rebased this PR onto #213 and moved MergeLeafTypes into schema-dts-lib, while keeping the leaf export change in the generator. I also reran the generator snapshots and the schema-dts build/typecheck flow on top of the new split.

/*modifiers=*/ [],
factory.createImportClause(
SyntaxKind.TypeKeyword,
/*isTypeOnly=*/ true,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this overload is deprecated, any reason you used it instead of the existing code that passed SyntaxKind.TypeKeyword?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched this back to SyntaxKind.TypeKeyword to match #213; the boolean overload change was accidental during the split.

@Eyas
Copy link
Copy Markdown
Collaborator

Eyas commented Mar 23, 2026

Can you also run:

npm run fix:prettier

to update the formatting of the .ts and .md files?

Switch helper_types.ts back to SyntaxKind.TypeKeyword to match google#213.

Also run npm run fix:prettier to apply the requested TS/MD formatting updates.
@cochinescu
Copy link
Copy Markdown
Contributor Author

Sure, ran npm run fix:prettier and pushed the formatting updates.

@Eyas Eyas merged commit 324ee86 into google:main Mar 23, 2026
5 checks passed
@cochinescu cochinescu deleted the merge-leaf-types branch March 23, 2026 19:19
@Eyas
Copy link
Copy Markdown
Collaborator

Eyas commented Mar 23, 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.

Add util type for merge multiple types

2 participants