-
Notifications
You must be signed in to change notification settings - Fork 75
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
Inherit top-level type (e.g. PlainMessage) #230
Comments
Hey Brian, thanks for this issue! The behavior is a design choice - the type is an exact representation for a message cloned with the spread operator: I'm aware that this is not always helpful in practice. Making The rationale for Expect to see some updates regarding this soonish. In the meantime, I don't see any complications from using your own recursive version of |
A recursive version of import type { Message } from "@bufbuild/protobuf";
export type Plain<T extends Message> = {
[P in keyof T as T[P] extends Function ? never : P]: PlainField<T[P]>;
};
// prettier-ignore
type PlainField<F> =
F extends (Date | Uint8Array | bigint | boolean | string | number) ? F
: F extends Array<infer U> ? Array<PlainField<U>>
: F extends ReadonlyArray<infer U> ? ReadonlyArray<PlainField<U>>
: F extends Message ? Plain<F>
: F extends OneofSelectedMessage<infer C, infer V> ? { case: C; value: Plain<V> }
: F extends { case: string | undefined; value?: unknown } ? F
: F extends { [key: string|number]: Message<infer U> } ? { [key: string|number]: Plain<U> }
: F;
type OneofSelectedMessage<K extends string, M extends Message> = {
case: K;
value: M;
}; |
@timostamm Thanks! The |
@timostamm that |
Absolutely, @sjbarag. We're just wrapping up some work on the plugin framework, but this issue is up next! |
@faustbrian @sjbarag We landed #308 today, which makes the current |
Excellent, thanks @smaye81 ! |
I have some user-facing functions that take
PlainMessage<T>
as input. The problem is thatPlainMessage
doesn't seem to trickle down to properties that themselves are messages. Take the below snippets as an example:Protobuf
When using
PlainMessage<T>
I would expect all properties ofT
that are also messages to be also referenced asPlainMessage
rather than expecting the (full)Message
. Is this an intentional design choice and can this be worked around without a custom type outside the library or is this an oversight? Thanks in advanced!The text was updated successfully, but these errors were encountered: