Skip to content

fix(typescript-input): preserve declared property order (#898)#3067

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

fix(typescript-input): preserve declared property order (#898)#3067
schani merged 1 commit into
masterfrom
agent/fix-issue-898

Conversation

@schani

@schani schani commented Jul 21, 2026

Copy link
Copy Markdown
Member

Bug

Given TypeScript class input:

class A {
    name: string;
    age: number;
}

quicktype's Swift output alphabetized the fields instead of preserving
declaration order:

struct A {
    let age: Double
    let name: String
}

This breaks the generated memberwise initializer's parameter order and,
more generally, silently reorders any output that's sensitive to property
order.

Root cause

packages/quicktype-typescript-input/src/index.ts invokes
typescript-json-schema to convert TypeScript sources into a JSON Schema,
but never passed the propOrder setting. Without it, typescript-json-schema
emits no propertyOrder metadata on schema definitions, so downstream
JSONSchemaInput has no order information to work with and falls back to
alphabetical/insertion order from the schema object.

quicktype already has a mechanism for this: JSONSchemaInput reads an
optional quicktypePropertyOrder field off each schema definition
(packages/quicktype-core/src/input/JSONSchemaInput.ts), it just was never
populated for TypeScript-source input.

Fix

  • Enable propOrder: true in the typescript-json-schema settings.
  • Copy the emitted propertyOrder array from each schema definition onto
    quicktypePropertyOrder, which JSONSchemaInput already consumes.

Tests

Added a regression test in test/unit/typescript-input.test.ts that compiles
a TypeScript class through schemaForTypeScriptSources and then through
quicktype to Swift, asserting name is emitted before age, matching
declaration order.

This bug is specific to the "TypeScript source as input" path
(--src-lang typescript), which starts from .ts files rather than JSON or
JSON Schema fixtures, so it isn't expressible via the repo's JSON/JSON Schema
fixture harness (test/inputs/json, test/inputs/schema) — a unit test is
the appropriate coverage here per repo conventions.

Verification

  • npm run build passes.
  • npx vitest run — all 171 unit tests pass (26 files), including the new
    regression test.
  • Manual repro: node dist/index.js --lang swift --src-lang typescript A.ts
    with the class above now emits name before age in the generated
    Swift struct.

Fixes #898

🤖 Generated with Claude Code

typescript-json-schema was invoked without propOrder enabled, so
generated JSON Schemas had no property-order metadata and downstream
languages (e.g. Swift) alphabetized fields instead of preserving the
TypeScript declaration order.

Enable propOrder in the typescript-json-schema settings and copy the
resulting propertyOrder metadata onto quicktype's existing
quicktypePropertyOrder field, which JSONSchemaInput already honors.

Covered by a new unit test in test/unit/typescript-input.test.ts that
compiles a TypeScript class through to Swift output and asserts
property order is preserved; this path (TypeScript source as input)
isn't reachable through the JSON/JSON Schema fixture harness, which
starts from JSON/schema files rather than TS sources.

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

Property order is not preserved with TypeScript input

1 participant