Git Product home page Git Product logo

Comments (4)

thesayyn avatar thesayyn commented on May 24, 2024 1

@NfNitLoop yes that would be great. Also, a clear description of the problem would make it easier for me to solve.

from protoc-gen-ts.

NfNitLoop avatar NfNitLoop commented on May 24, 2024

Just adding some extra detail to this ticket for why strict mode is important.

Currently if you have a proto like:

message Example {
    oneof foo_or_bar {
        Foo foo = 1;
        Bar bar = 2;
    }
}

then the Example type will get generated with:

get foo(): Foo {
    return pb_1.Message.getWrapperField(this, Foo, 1) as Foo;
}

This advertises that Foo is unconditionally available, but in fact sometimes it can be undefined.

I've been confused a couple times when my TypeScript code ran into undefined values that shouldn't have been possible according to annotated types. :)

from protoc-gen-ts.

thesayyn avatar thesayyn commented on May 24, 2024

You are definitely right about this. getters should be annoted as possibly return undefined cause they are optional. May be we could leverage a feature of typescript which could be some kind of "optional chaining feature" designed for "return" statements. Or maybe we could just use Type | undefined | null as type annotation.

I'm not sure what we should use.

from protoc-gen-ts.

NfNitLoop avatar NfNitLoop commented on May 24, 2024

Ah, I saw that this issue was closed, so I thought the as Foo (vs. as Foo|undefined) issue had been fixed. But I guess the main bug here was different.

Should I open a separate issue for the Foo vs. Foo|undefined type problem?

(Unrelated: I'm using the generated code in Deno (with a very small manual update) and it seems to be working well so far!)

from protoc-gen-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.