-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update debugJsonValue to accept unknown #535
Conversation
If this happened during parsing of a valid JSON value, it is a bug. Note that import { Struct } from "@bufbuild/protobuf";
Struct.fromJson(undefined); The compiler should error with Can you provide details on how this error occurred? |
It was indeed not a valid JSON, but called with undefined as first parameter: |
That should be caught by the TypeScript compiler: import { Duration, JsonValue } from "@bufbuild/protobuf";
function somethingThatCouldReturnUndefined(): JsonValue | undefined {
return undefined;
}
Duration.fromJson(somethingThatCouldReturnUndefined());
// TS2345: Argument of type 'JsonValue | undefined' is not assignable to
// parameter of type 'JsonValue'. Type 'undefined' is not assignable to type
// 'JsonValue'. We could change the signature: - fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>)
+ fromJson(jsonValue: JsonValue | undefined, options?: Partial<JsonReadOptions>) But it would be very unusual for a function to accept |
It wasn't because one of the branch was returning I'd advocate for |
👍 that is reasonable. Changing the default case to return |
Updated with this improvement! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 🙂
Pushed up a commit with updated bundle size benchmark (make bench
).
It made the package 3 bytes smaller, which is an absolute win |
## What's Changed * #533 by @srikrsna-buf * #535 by @GauBen ## New Contributors * @GauBen made their first contribution in #535. **Full Changelog**: https://github.com/bufbuild/protobuf-es/compare/v1.3.0..v1.3.1
Hey! We started migrating a large code base to protobuf, we'll probably be uncovering a few bugs on the way.
This merge request addresses an issue regarding
debugJsonValue
: