Skip to content

fix(typescript): add undefined to index signature for optional properties - #3472

Merged
schani merged 3 commits into
masterfrom
triage-three-issues-on-master
Sep 6, 2026
Merged

fix(typescript): add undefined to index signature for optional properties#3472
schani merged 3 commits into
masterfrom
triage-three-issues-on-master

Conversation

@schani

@schani schani commented Sep 6, 2026

Copy link
Copy Markdown
Member

Fixes #3123

Why

An interface with both properties and a typed additionalProperties gets an index signature. TypeScript requires every declared property to be assignable to it. Optional properties have type T | undefined, and the index signature omitted undefined, so tsc --strict failed with TS2411:

error TS2411: Property 'id' of type 'string | undefined' is not assignable to 'string' index type 'string | number'.

The fixtures never caught this because test/fixtures/typescript/tsconfig.json disabled strictNullChecks.

What

  • Append undefined (void for Flow) to the index signature when any property is optional.
  • Dedupe index signature members. class-map-union.schema previously emitted boolean | BarObject | boolean | number | BarObject | boolean | BarObject | string.
  • Emit just any/unknown when additionalProperties is any, instead of unknown | number.
  • Enable strictNullChecks in the TypeScript fixture. With it on, the existing class-with-additional.schema reproduces the TS2411 error before the fix, and class-map-union.schema covers the dedupe and any cases.

Supersedes #3127.

🤖 Generated with Claude Code

…ties

An interface with both properties and typed additionalProperties emitted
an index signature that omitted `undefined`, so optional properties of
type `T | undefined` failed `tsc --strict` with TS2411. Also dedupe the
index signature members and drop the union when additionalProperties is
`any`.

Fixes #3123

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@schani
schani enabled auto-merge (squash) September 6, 2026 02:19
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

Generated-output differences

162 files differ — 125 modified, 37 new, 0 deleted
3017 changed lines — +2848 / −169

Open the generated-output report →

PHP emits no class for a top-level object with additionalProperties,
so the driver echoes the input and the negative sample cannot fail.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

Generated-output differences

161 files differ — 125 modified, 36 new, 0 deleted
3015 changed lines — +2846 / −169

Open the generated-output report →

class-with-additional.schema already covers an optional property next
to typed additionalProperties, and class-map-union.schema covers the
dedupe and any cases. With strictNullChecks on they catch TS2411.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

Generated-output differences

125 files differ — 125 modified, 0 new, 0 deleted
338 changed lines — +169 / −169

Open the generated-output report →

@schani
schani merged commit e1c1d85 into master Sep 6, 2026
35 checks passed
@schani
schani deleted the triage-three-issues-on-master branch September 6, 2026 03:23
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.

[BUG]: TS compile error when properties and additionalProperties are incompatible

1 participant