Giter Site home page Giter Site logo

Comments (4)

jcready avatar jcready commented on June 1, 2024

You should be able to create these functions yourself (playground):

function isKeyof<T extends {}>(t: T, key: string): key is string & keyof T {
    return key in t;
}

function getEnumValueOrDefault<T extends {}>(e: T, key: string): 0 | T[string & keyof T] {
    return isKeyof(e, key) ? e[key] : 0;
}

from protobuf-ts.

dimo414 avatar dimo414 commented on June 1, 2024

Yeah I agree it's possible to workaround, but I was hoping protobuf-ts could include these e.g. in the generated code of each enum so it's right on the type, rather than something we need to pull together or go find.

from protobuf-ts.

jcready avatar jcready commented on June 1, 2024

The enums are just TS enums. No extra properties or methods can be added and have them be TS enums.

from protobuf-ts.

dimo414 avatar dimo414 commented on June 1, 2024

Fair enough; well IMO there's room for protobuf-ts to improve the ergonomics of string->enum lookups vs. what TypeScript provides out of the box, but I understand if you disagree.

from protobuf-ts.

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.