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

fromPartial typescript design #108

Closed
pyramation opened this issue Jun 1, 2022 · 2 comments
Closed

fromPartial typescript design #108

pyramation opened this issue Jun 1, 2022 · 2 comments

Comments

@pyramation
Copy link
Collaborator

pyramation commented Jun 1, 2022

For certain protos (google) typescript doesn't like the Exact and DeepPartial (#107)

These meta typescript types create an issue that has been talked about here on stackoverflow as well as the ts-proto issues here

These Exact and DeepPartial types were discussed for ts-proto here

They honestly seem to be adding more issues that what they're providing — to my understanding, you can call fromPartial and it allows properties to be optional, and provides defaults.

What if we can do something much simpler for the typescript compiler, like explicitly define a typescript interface that has optional properties? Potential drawback for nested properties, but I think it could be worth adding a flag for.

UPDATE: our immediate issue can be solved similar to how this issue which was fixed by this PR

@pyramation
Copy link
Collaborator Author

pyramation commented Jun 1, 2022

example

current method

  fromPartial<I extends Exact<DeepPartial<Any>, I>>(object: I): Any {
    const message = createBaseAny();
    message.typeUrl = object.typeUrl ?? "";
    message.value = object.value ?? new Uint8Array();
    return message;
  }

new updated version

  fromPartial(object: AnyFromPartial): Any {
    const message = createBaseAny();
    message.typeUrl = object.typeUrl ?? "";
    message.value = object.value ?? new Uint8Array();
    return message;
  }

where in this new world, we would have two types instead of one

  interface AnyFromPartial {
      typeUrl?: string;
      value?: Uint8Array;
  }

  interface Any {
      typeUrl: string;
      value: Uint8Array;
  }

@webmaster128 do you think there is something like this we can do that's more explicit and simplifies things for the typescript compiler?

@pyramation
Copy link
Collaborator Author

looks typescript is much much happier without Exact.

Our immediate issue can be solved similar to how this issue which was fixed by this PR

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

No branches or pull requests

1 participant