fix(typescript): add undefined to index signature for optional properties - #3472
Merged
Conversation
…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
enabled auto-merge (squash)
September 6, 2026 02:19
Generated-output differences162 files differ — 125 modified, 37 new, 0 deleted |
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>
Generated-output differences161 files differ — 125 modified, 36 new, 0 deleted |
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>
Generated-output differences125 files differ — 125 modified, 0 new, 0 deleted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3123
Why
An interface with both
propertiesand a typedadditionalPropertiesgets an index signature. TypeScript requires every declared property to be assignable to it. Optional properties have typeT | undefined, and the index signature omittedundefined, sotsc --strictfailed with TS2411:The fixtures never caught this because
test/fixtures/typescript/tsconfig.jsondisabledstrictNullChecks.What
undefined(voidfor Flow) to the index signature when any property is optional.class-map-union.schemapreviously emittedboolean | BarObject | boolean | number | BarObject | boolean | BarObject | string.any/unknownwhenadditionalPropertiesisany, instead ofunknown | number.strictNullChecksin the TypeScript fixture. With it on, the existingclass-with-additional.schemareproduces the TS2411 error before the fix, andclass-map-union.schemacovers the dedupe andanycases.Supersedes #3127.
🤖 Generated with Claude Code