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 toPlainMessage idempotent #588

Merged
merged 1 commit into from
Oct 13, 2023

Conversation

haines
Copy link
Contributor

@haines haines commented Oct 13, 2023

This PR makes it possible to call toPlainMessage on a PlainMessage<T> object as well as a Message<T> instance.

The motivation for this change is the lack of exact types in TypeScript. Specifically, if I define a function that accepts a PlainMessage<T> as an argument, it's valid to pass a Message<T> instance as well, because it has all the properties necessary to satisfy the PlainMessage<T> interface.

If I need to ensure that I actually have a PlainMessage<T> inside the function (e.g. for the reasons described in connectrpc/connect-es#505), at the moment I have to type the parameter as T | PlainMessage<T>, and check with instanceof Message before calling toPlainMessage.

@CLAassistant
Copy link

CLAassistant commented Oct 13, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

Makes sense to me to support this for convenience 👍 Thank you for adding the test.

Could you add the following to the JSDoc?


If the argument is already a plain message, it is
returned as is.

Signed-off-by: Andrew Haines <andrew@haines.org.nz>
Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

LGTM!

@timostamm timostamm merged commit 828438a into bufbuild:main Oct 13, 2023
3 checks passed
@haines haines deleted the idempotent-to-plain-message branch October 13, 2023 15:56
@haines
Copy link
Contributor Author

haines commented Oct 13, 2023

Thanks!

@timostamm timostamm mentioned this pull request Oct 24, 2023
@timostamm
Copy link
Member

This was just released in v1.4.0.

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.

None yet

3 participants