Giter Site home page Giter Site logo

Comments (2)

paralin avatar paralin commented on May 29, 2024

Protobuf 3 cannot distinguish between unset fields and zero fields. The zero value is not sent on the wire.

from ts-proto.

stephenh avatar stephenh commented on May 29, 2024

Hi @biljecki ; unfortunately @paralin is right and this is just a fact of life with protobuf, that optional handling is really suboptimal/all over the place.

Per the arrays, I glanced at a fromJSON in our integration/simple directory and it is setting the array to []:

  fromJSON(object: any): Simple {
    return {
      name: isSet(object.name) ? globalThis.String(object.name) : "",
      age: isSet(object.age) ? globalThis.Number(object.age) : 0,
      createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined,
      child: isSet(object.child) ? Child.fromJSON(object.child) : undefined,
      state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0,
      grandChildren: globalThis.Array.isArray(object?.grandChildren)
        ? object.grandChildren.map((e: any) => Child.fromJSON(e))
        : [],

And the type of grandChildren is [].

As you can tell, many others have disliked proto3's optional behavior, and we have ~more than a few options for attempting to make them not suck, but there are pros/cons to each.

Happy to see doc/bug fix PRs if you have very specific behavior that needs improved/fixes bug, but otherwise I'm going to close this out. Thanks!

from ts-proto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.