Skip to content

Comments

Use typings generated from JSON Schemas.#5662

Draft
iclanton wants to merge 40 commits intomicrosoft:mainfrom
iclanton:use-json-schema-plugin
Draft

Use typings generated from JSON Schemas.#5662
iclanton wants to merge 40 commits intomicrosoft:mainfrom
iclanton:use-json-schema-plugin

Conversation

@iclanton
Copy link
Member

@iclanton iclanton commented Feb 22, 2026

Summary

Many Rush Stack packages define JSON Schemas for their config files and then maintain hand-written TypeScript interfaces to represent the same structure. This duplication leads to drift, missing documentation, and boilerplate. This PR integrates @rushstack/heft-json-schema-typings-plugin into the monorepo's standard rigs so that TypeScript type declarations are automatically generated from JSON Schemas at build time, replacing hand-written interfaces across the repo.

Here is a diff of the docs: iclanton/rushstack-docs-diff@405e303

Details

Rig integration:

  • Added @rushstack/heft-json-schema-typings-plugin as a build task in local-node-rig, local-web-rig, and decoupled-local-node-rig. Schemas with .schema.json extension produce .schema.json.d.ts files into temp/schema-ts (for compilation) and lib-dts (for publishing). The rigs also configure rootDirs so TypeScript can resolve the generated declarations alongside source files.

Packages migrated to generated types (hand-written interfaces removed):

  • heft — ICopyOperation, ICopyFilesPluginOptions, IDeleteOperation, IDeleteFilesPluginOptions, IRunScriptPluginOptions, ISetEnvironmentVariablesPluginOptions, IFileSelectionSpecifier, and all heft-plugin parameter types
  • rush-lib — IExperimentsJson, IApprovedPackagesJson, ICobuildJson, ICommonVersionsJson, IRushPluginsJson, IRushUserSettingsJson, ISubspacesJson, and others
  • credential-cache — ICredentialCacheEntry, ICredentialCacheJson
  • rig-package — IRigConfigJson
  • heft-plugins/* — 11 Heft plugins had their option interfaces replaced with schema-generated types (typescript, jest, lint, sass, storybook, api-extractor, webpack4/5, rspack, localization-typings, isolated-typescript-transpile)

Schema improvements:

  • Upgraded Heft schemas (heft-plugin.schema.json, copy-files-options.schema.json, delete-files-options.schema.json, heft.schema.json) to JSON Schema draft-2019-09, using $defs and unevaluatedProperties for cleaner type composition
  • Standardized title fields across all Rush schemas for consistent generated type names
  • Added description fields to api-extractor.schema.json definitions so generated types get proper JSDoc documentation
  • Created shared file-selection.schema.json for reuse across copy/delete schemas
  • Renamed plugin option schema files to use -options.schema.json suffix consistently

@rushstack/node-core-library changes:

  • Added 'draft-2019-09' to the JsonSchemaVersion type and implemented validation support using ajv/dist/2019

@rushstack/heft-json-schema-typings-plugin changes:

  • Fixed TSDoc parse warnings caused by @ characters in generated JSDoc comments (e.g., patternProperties keys like "^@[^\s]*$" are now wrapped in backtick code spans)

Other:

  • Moved .d.ts output from lib-commonjs to lib-dts in rush-lib and rush-sdk to align with the generated declarations workflow
  • The api-extractor integration was reverted in the final commit pending the plugin's next publish (the rig's decoupled-local-node-rig uses a published version, so the regex fix isn't available yet)

How it was tested

  • Ran rush build across the repo and verified all affected projects compile successfully
  • Confirmed generated .schema.json.d.ts files match the expected types via snapshot tests in heft-json-schema-typings-plugin-test
  • Verified .api.md review files are updated correctly with no unexpected (undocumented) markers
  • Checked that the heft-plugin.schema.json draft-2019-09 upgrade with unevaluatedProperties: false validates correctly at runtime
  • Added a unit test for JsonSchema draft-2019-09 support in node-core-library

Impacted documentation

  • JSON schema URLs referenced via $schema in config files are unchanged, but the schema content itself is updated

@github-project-automation github-project-automation bot moved this to Needs triage in Bug Triage Feb 22, 2026
- Remove dTsFilesInputFolderName from DeepImportsPlugin config in rush-lib webpack
- Update copyEmptyModules.js to only generate JS stubs without .d.ts copying
- Refactor rush-sdk generate-stubs.ts to only create JS stubs
- Add copy-files-plugin task to copy .d.ts files from rush-lib/lib-dts to rush-sdk/lib-dts
- Declarations now live only in lib-dts, not duplicated in lib-commonjs
@iclanton iclanton force-pushed the use-json-schema-plugin branch from 37dc842 to aa46a62 Compare February 22, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

1 participant