-
Notifications
You must be signed in to change notification settings - Fork 8
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
Nested Structure generation without defaults #23
Conversation
e38bde5
to
cfd24b4
Compare
36c36b8
to
68d9389
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, let's just cut the generated comment thing. i think it creates more confusion than it resolves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some nittish issues about the way the printing function handles nesting
encoder/generator.go
Outdated
// Render a string containing a Typescript semantic equivalent to the provided | ||
// Value, if possible. | ||
// | ||
// The provided Value must be a simple expression (loosely defined, until | ||
// something more precise is understood); e.g., this will NOT render a struct | ||
// literal. | ||
func tsprintField(v cue.Value) (string, error) { | ||
func tsprintField(v cue.Value, optionals ...int) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be variadic? Unless i'm missing something, it seems like it should be sufficient to just make it a single int corresponding to the nesting level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, just want to do something equivalent to default parameter to avoid updating everywhere :D, apparently in go there is no such thing... This is the equivalent version i found in go...
Will do something static.
It's fine to just expect all regular calls to pass 0 as a second parameter.
If it really bugs you, you can always make a separate "inner" function for
the recursive call that has a level parameter, and the current
`tsprintField` will just call that inner one, adding the 0 as a second
parameter.
…On Thu, Sep 16, 2021 at 9:55 AM ying-jeanne ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In encoder/generator.go
<#23 (comment)>:
> // Render a string containing a Typescript semantic equivalent to the provided
// Value, if possible.
//
// The provided Value must be a simple expression (loosely defined, until
// something more precise is understood); e.g., this will NOT render a struct
// literal.
-func tsprintField(v cue.Value) (string, error) {
+func tsprintField(v cue.Value, optionals ...int) (string, error) {
yes, just want to do something equivalent to default parameter to avoid
update everywhere :D, apparently in go there is no such thing. Will do
something static.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAFIX7O3CW6TSIADO6IIX3UCHZOTANCNFSM5C3M57TA>
.
|
probably better as you said, i don't really like this version neither since it fixed the rest of input as int also... |
This PR is to generate the Nested Structure from cue to typescript. It doesn't fully support the default generation for the following case yet.
The expected result should be
instead of