fix(compiler): include null in TS map value types for optional map values - #4108
Open
ayush00git wants to merge 2 commits into
Open
ayush00git wants to merge 2 commits into
ayush00git wants to merge 2 commits into
Conversation
…lues For a field like `map<string, optional string> attrs = 1;`, the JavaScript generator emitted the TypeScript type `Map<string, string>` while the runtime schema registration correctly marked the map value nullable with `.setNullable(true)`, so deserialized null values violated the declared type. Pass `nullable=field_type.value_optional` for the map value type in generate_type, matching how list elements already handle optionality, so the type becomes `Map<string, string | null>`. Claude-Session: https://claude.ai/code/session_01YcPbRyTJYmU8t6mkGCbnUf
This branch has not been deployed
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.
What does this PR do?
For a schema field like
map<string, optional string> attrs = 1;, the JavaScript generator declared the TypeScript type asMap<string, string>while the same generated file's runtime schema registration correctly emits.setNullable(true)on the map value type, so the declared TS type contradicted the runtime schema and deserialized null values violated it. The fix is one line: the MapType branch ofgenerate_typenow passesnullable=field_type.value_optionalfor the value type, producingMap<string, string | null>, matching how list elements already handle optionality.Verified with a new regression test that fails without the generator change; the full compiler suite (
fory_compiler/tests) passes.