Skip to content
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

Make wrappers more lenient #291

Merged
merged 1 commit into from
Nov 7, 2022
Merged

Make wrappers more lenient #291

merged 1 commit into from
Nov 7, 2022

Conversation

timostamm
Copy link
Member

Fixes #283 by removing code path that errors. We can easily and reliably determine whether a field is already wrapped by checking if it is instanceof Message.

Fixes #283 by removing code path that errors. We can easily and reliably determine whether a field is already wrapped by checking if it is `instanceof Message`.
@timostamm timostamm requested a review from smaye81 November 7, 2022 15:18
Comment on lines +21 to +25
describe("mixing message instances", () => {
const message = new TS_MessageFieldMessage();
message.messageField = new JS_MessageFieldMessage_TestMessage({
name: "foo",
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This covers the use case of #283 by using a message of the JavaScript generated code for a field of a message from the TypeScript generated code, proving that we no longer error.

Also added many more tests around wrappers.

Comment on lines +82 to 84
wrapField(value: number): DoubleValue {
return new DoubleValue({value});
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This simplifies the generated code by making the internal function wrapField idempotent instead of this FieldWrapper. I don't like changing this, but it the generated code does look quite a bit nicer...

@timostamm timostamm merged commit fd2c4a8 into main Nov 7, 2022
@timostamm timostamm deleted the tstamm/more-lenient-wrappers branch November 7, 2022 15:35
smaye81 pushed a commit that referenced this pull request Nov 11, 2022
@smaye81 smaye81 mentioned this pull request Nov 23, 2022
smaye81 added a commit that referenced this pull request Nov 23, 2022
This release includes the following:

## Enhancements
* Add a toJSON method to messages by @smaye81 in #306
* Add an unpack function to `google.protobuf.Any` by @smaye81 in #303
* Make generated imports look more normal by @dimitropoulos in #298
⚠️ Note that as a result of this PR, import statements in your
generated code will contain diffs when generated with `v0.3.0` as the
import statements will have spaces added. For example:
   ```diff
   - import {FooMessage} from './foo_message_pb.js';
   + import { FooMessage } from './foo_message_pb.js';
   ```
* Add print function with tagged template literal by @yukukotani in #279
* Enhance the `Any.is` function by @smaye81 in #294
* Make wrappers more lenient by @timostamm in #291

## Bugfixes
* Fix map equality by @calebdoxsey in #305
* Make `tsNocheck` work correctly by @yukukotani in #275

## New Contributors
@calebdoxsey made their first contribution in #305
@yukukotani made their first contributions in #275 and #279
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.

Too strict type checking during serialization
2 participants