Repository navigation
Jsonify: Fix optional properties leaking undefined into the key set - #1484
Merged
sindresorhus merged 3 commits intoJul 13, 2026
Merged
Conversation
`FilterJsonableKeys` maps each property to its own name and reads all
values back out with an indexed access. Reading an optional property adds
`undefined` to the result, so for `{a: string; b?: string}` the key union
became `"a" | "b" | undefined`. Feeding that union to `Pick` silently
builds an object whose key set includes `undefined`, and re-applying
`Jsonify` to that output walks the corrupted key set, computes the
illegal lookup `T[undefined]`, and collapses the object to `{}`.
Excluding `undefined` from the union keeps the key set clean and makes
`Jsonify<Jsonify<T>>` equal `Jsonify<T>`.
Fixes discovered downstream in inngest/inngest#4483.
sindresorhus
approved these changes
Jul 6, 2026
som-sm
requested changes
Jul 11, 2026
Comment on lines
36
to
38
| type JsonifyObject<T extends object> = { | ||
| [Key in keyof Pick<T, FilterJsonableKeys<T>>]: Jsonify<T[Key]>; | ||
| }; |
Collaborator
There was a problem hiding this comment.
FilterJsonableKeys is actually not required at all, that's just unnecessary code.
Updating JsonifyObject to the following is a better fix:
Suggested change
| type JsonifyObject<T extends object> = { | |
| [Key in keyof T as T[Key] extends NotJsonable ? never : Key]: Jsonify<T[Key]>; | |
| }; |
This passes all the test cases.
Contributor
Author
There was a problem hiding this comment.
Ohhh you're right, updated! 👍 Thank you!
som-sm
approved these changes
Jul 13, 2026
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.
FilterJsonableKeysmaps each property to its own name and reads all values back out with an indexed access. Reading an optional property addsundefinedto the result, so for{a: string; b?: string}the key union became"a" | "b" | undefined. Feeding that union toPicksilently builds an object whose key set includesundefined, and re-applyingJsonifyto that output walks the corrupted key set, computes the illegal lookupT[undefined], and collapses the object to{}.Excluding
undefinedfrom the union keeps the key set clean and makesJsonify<Jsonify<T>>equalJsonify<T>.Fixes discovered downstream in inngest/inngest#4483.