Skip to content

fix(typescript-input): strip brace-wrapped types from JSDoc @type tags#2968

Merged
schani merged 1 commit into
masterfrom
agent/fix-issue-2695
Jul 21, 2026
Merged

fix(typescript-input): strip brace-wrapped types from JSDoc @type tags#2968
schani merged 1 commit into
masterfrom
agent/fix-issue-2695

Conversation

@schani

@schani schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

Bug

TypeScript input properties documented with a JSDoc @type {...} tag (e.g.
@type {string}) produced invalid "type": "{string}" in the generated
JSON Schema instead of "type": "string", when converting via
--src-lang typescript --lang schema.

export type Person = {
  /**
   * @type {string}
   */
  name: string;
}

produced:

{ "type": "{string}", "title": "name" }

instead of the expected:

{ "type": "string", "title": "name" }

Because the resulting schema is invalid JSON Schema, feeding it back into
quicktype for any other target language then failed hard with
Invalid type {string} in JSON Schema.

Root cause

packages/quicktype-typescript-input wraps the typescript-json-schema npm
package (a normal, unforked dependency). That package hardcodes type as an
always-on "validation keyword": when it sees a JSDoc @type {TypeExpression}
tag on a symbol, it copies the tag's raw text — including the surrounding
braces from the JSDoc syntax — verbatim into the generated schema's type
field, overwriting the correct type inferred from the TypeScript type. This
behavior isn't configurable via the settings quicktype passes in, so it can't
be disabled at the call site.

Fix

Added a small post-processing pass (sanitizeTypeAnnotations) in
packages/quicktype-typescript-input/src/index.ts, run on the schema
right after generateSchema() returns (in the same spirit as the existing
post-processing already done in that function). It walks the schema
recursively and strips a single pair of surrounding braces from any string
type value, e.g. turning "{string}" into "string".

Test coverage

Added a regression test in test/unit/typescript-input.test.ts reproducing
the issue's exact TypeScript input (a @type {string}-documented property
plus a Required<Person> usage) and asserting the generated schema's
property type is the plain string "string". The test was confirmed to fail
on unfixed code (Received: "{string}") before the fix was applied.

Verification

  • npm run build — passes
  • npm run test:unit — 25 files, 164 tests pass (including the new
    regression test)
  • Manually re-ran the issue's repro:
    node dist/index.js --src person.ts --src-lang typescript --lang schema
    now emits "type": "string" instead of "type": "{string}"
  • Manually confirmed the cascading failure is also fixed: generating Go
    output from the same TypeScript input (--lang go) now succeeds instead
    of erroring with Invalid type {string} in JSON Schema
  • This bug is on the TypeScript-as-input-language path, which isn't
    exercised by the JSON/JSON-Schema fixture system (that operates on
    JSON/JSON-Schema inputs, not TypeScript source), so unit test coverage
    in test/unit/ is the appropriate mechanism here, consistent with how the
    rest of that file already tests schemaForTypeScriptSources. CI will run
    the full fixture and unit test suites.

Fixes #2695

🤖 Generated with Claude Code

#2695)

typescript-json-schema treats a property's `@type {string}` JSDoc tag as a
"type" validation keyword and copies its raw text verbatim, braces
included, into the generated schema's `type` field. That produces invalid
JSON Schema like `"type": "{string}"`, which also makes quicktype fail hard
when that schema is later consumed for any other output language.

Sanitize the schema after generateSchema() runs: strip a single pair of
surrounding braces from any string `type` value.

Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
@schani
schani merged commit 3003456 into master Jul 21, 2026
52 of 84 checks passed
@schani
schani deleted the agent/fix-issue-2695 branch July 21, 2026 00:35
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.

Typescript -> JSON Schema Output contains "type": "{string}" instead of "type": "string"

1 participant