Comments (10)
Fields marked with 'repeated' or 'map' are missing the optional indicator; '?' in the Message constructor signature.
I am not sure whether they were correct in the past. right now the constructor takes field presence into consideration when generating the constructor. back then the idea was to make everything optional so that they can be filled later with setters but with the introduction of one-of-fields and checks we have to take field absence into consideration.
Hence, I am opinion of preserving the current behavior as it is stricter than the previous behavior and warn you upfront but this can be reverted if it creates so much overhead of changing the written code.
I would rather listen to users rather than taking a strong opinion on this. what do you think about how this should be?
from protoc-gen-ts.
Pretty sure that all fields are/should-be optional.
I posted comment about "oneof" on your "things to do next" thread.
"oneof" tracks internal field presence in its own ways... so should not be interact with the constructor form.
and: 'oneof' means: at MOST one of the fields is present, not a guarantee "one of the fields" is present.
It is totally legitimate to have a one-of field be empty.
from protoc-gen-ts.
I'm not sure what issue there is with 'map'...
But, fwiw, I noticed this in the spec, in case it is relevant: Map Field Equivalence
from protoc-gen-ts.
Pretty sure that all fields are/should-be optional.
I posted comment about "oneof" on your "things to do next" thread.
"oneof" tracks internal field presence in its own ways... so should not be interact with the constructor form.
and: 'oneof' means: at MOST one of the fields is present, not a guarantee "one of the fields" is present.
It is totally legitimate to have a one-of field be empty.
this is definitely the expected behavior when the data is given via constructor. I must have broken it while refactoring the codebase. so by this logic and since one-of fields are mutually exclusive the generated code should look like below regardless of syntax or field presence.
{field?: string} & {oneoffield1?: string, oneoffield2?: never} & {oneoffield1?: never, oneoffield2?: string}
from protoc-gen-ts.
the reason we generate union types for one-of-fields is to warn the user through the compile-time errors hence the user knows which properties can be mutually present.
from protoc-gen-ts.
I'm not sure what issue there is with 'map'...
But, fwiw, I noticed this in the spec, in case it is relevant: Map Field Equivalence
I have other plans of using Map
for map<k, v>
which will be in memory until the serialize
is called.
from protoc-gen-ts.
"the reason we generate union types for one-of-fields"
Hmm, that relates to the gist of my "Things to do" comment.
I don't see a union type being created.
Especially, I don't see a: get value(): ValueUnionType { return ... the value variant currently set ...}
I have synthesized the type and accesor for my simple TypedMsg* by patching:
syntax="proto3";
message TypedMsg {
oneof value {
bool boolValue = 3;
int32 intValue = 4;
string strValue = 5;
}
}
from protoc-gen-ts.
is the generated message supposed to have a field called value
alongside the one-of-fields?
from protoc-gen-ts.
I think so... the accessor 'value' returns the one-of {boolValue, intValue or strValue} that is actually set.
I've seen two implementation styles:
a) maintain 3 individual fields, and an indicator for which is 'set', and 'value' returns the field that is set.
and unset a field when the one-of the others is set (complex but builds on the existing field structure)
b) have 1 field for 'value' and the other 3 field accessors return value or undefined, based on the indicator.
(somewhat simpler, because there is only one field that can be set) [sets 'hasField' ... to make it clear]
Either way, you need to track the last one-of the fields to be set...
[.js implementation seems to be based on (a); Java is based on (b) ]
Take a look at the link into the "Dart" API... (in the other thread)
See if i got it right.
from protoc-gen-ts.
Hey @jackpunt.
I have landed a fix for this along with the support for one-of-fields and ECMAScript maps.
please try version 0.3.6-rc5
it should be working now.
feel free to reopen. if there is a problem
from protoc-gen-ts.
Related Issues (20)
- Generation with target=web HOT 3
- Cannot use ‘in’ operator to search for ‘Array’ in undefined; HOT 2
- Get `Error: EAGAIN: resource temporarily unavailable, read` when maybe many files are specified as input HOT 1
- Support Promises in Server Definition
- npm package needs publishing to include fix for typescript >= 5 HOT 8
- The namespace 'Google protobuf' does not have an exported member 'BinaryWriter' HOT 1
- `toObject()` inferred type too long when compiled with `declaration: true` HOT 1
- More fleshed out example
- Proto with oneof and other field is generated as union instead of intersect
- `Property 'xy' of type 'z' is not assignable to 'string' index type 'UntypedHandleCall'.` for class properties
- Add `as const` to UnimplementedService definition
- TSC error with compiler option noUnusedLocals HOT 2
- import_style=es6 ? HOT 1
- Consuming JSON For Tests and Converting To Protoc HOT 1
- I need to generate file interface IUser {} HOT 3
- Property 'Buffer' does not exist on type 'typeof globalThis' HOT 2
- [rust] Error starting the proto build with new rust wasm package. Error when executing /usr/bin/protoc-gen-ts HOT 1
- [rust] proto3 optional fields support
- methodName conflict HOT 1
- snake_case to camelCase conversion HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protoc-gen-ts.