-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[TS] Feature Request: Make optional field getters return undefined
(instead of null
) if the value is not set
#7656
Comments
At the same time, if a table field is |
Hi, developers. Any update or thoughts about this? IMHO it makes lot of sense. |
This issue is stale because it has been open 6 months with no activity. Please comment or label |
Just keeping this alive. |
Hi, not a TS person, but are you envisioning a flag that changes every accessor or adding a key to the schema? The global flag seems too coarse grained for sufficiently large projects. I think its plausible that depending on the type Adding field or table level options seems like more work but ultimately a better solution, e.g.
|
I would say this should come as a flatc option, being a language specific matter. If you use 'undefined' rather than 'null' in your project you would need to add such flag everywhere in the schema otherwise. Usually you use one of them and not mix them. |
This issue is stale because it has been open 6 months with no activity. Please comment or label |
Ping |
Flatbuffers version:master
OS: Mac OS BigSur
If I wanted to create a flatbuffers table that represents the following TS type:
which is the same as:
..., I would define the following table, which represents a type with an optional field
name
of typestring
.When generating the TS code of
Foo
table, the obtained code is as follows:The return type of
name()
method isstring|null
, whereasstring|undefined
would perfectly match the optional fields defined in TS as exposed above.I'm finding myself manually converting types due to this. It would be great to have a
flatc
option to indicate that optional field getters should returnundefined
instead ofnull
if a value is not set.Is there any reason for not having this?
Would you be willing to accept a contribution for this feature request?
The text was updated successfully, but these errors were encountered: