Go Optional Function Argument Support #2442
Labels
effort/large
Large work item – several weeks of effort
feature-request
A feature should be added or improved.
p1
Milestone
The Go runtime and code generation don't currently support TS functions with optional arguments. In JSII libraries currently, most methods that accept complex data structures use interfaces with optional properties. These are currently handled "correctly" implicitly because when these are "zero values" in go, they are serialized as undefined and therefore not passed over the wire.
A more explicit approach will likely have to be taken here. A couple of options that have been discussed previously.
Wrapper types. This would cause us to wrap all optional types in some wrapper type. This however has the huge downside of when a type goes from required to optional in TS, a breaking change would occur in the generated Go code. This is likely untenable.
Pointers everywhere. All types in all public APIs would be converted from
T
to*T
. This would allow users to pass null pointers for optional values. This also has some huge downsides. The first being, users can also pass null pointers to non-optional types and the go compiler wouldn't complain, these would manifest as a runtime crash. Additionally, increased verbosity is an issue. In Go you cannot pass a pointer to a primitive type anonymously. iecallThing(&"MyString")
. Instead the user would have to allocate a variable with"MyString"
and specify a pointer to that. This however could be mitigated by creating wrapper types from "pointer to a thing".The text was updated successfully, but these errors were encountered: