Skip to content

TypeScript: quote property names that are not valid identifiers - #300

Open
sebxt wants to merge 1 commit into
1Password:mainfrom
sebxt:fix/typescript-quote-non-identifier-fields
Open

sebxt wants to merge 1 commit into
1Password:mainfrom
sebxt:fix/typescript-quote-non-identifier-fields

Conversation

@sebxt

@sebxt sebxt commented Oct 20, 2026

Copy link
Copy Markdown

typescript_property_aware_rename only quoted names containing -. A field renamed with serde to something like @type, schema.org or 2fa was written bare and the generated interface failed to parse.

This change quotes the name whenever it is not a plain identifier: the first character must be a letter, _ or $, and the rest letters, digits, _ or $. Names that were valid before are emitted unchanged, and - names are still quoted, so existing snapshots do not change.

Changes:

  • core/src/language/typescript.rs: identifier check in typescript_property_aware_rename.
  • New TypeScript snapshot test can_quote_non_identifier_field_names covering @type, schema.org, 2fa and $ref (which stays unquoted).

Testing:

  • cargo test -p typeshare-core --test snapshot_tests passes; the new test fails without the generator change.
  • tsc --noEmit (TypeScript 5.6.3) reports 5 syntax errors on the old output and none on the new one.

Fixes #299

Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>

This branch has not been deployed

No deployments
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: field renamed to a non identifier string produces invalid TypeScript

1 participant