Skip to content

Interpolation of Optional values #790

Answered by cueckoo
cueckoo asked this question in Q&A
Discussion options

You must be logged in to vote

Original reply by @mpvl in cuelang/cue#790 (comment)

I would typically write x: *"\(optional)" | "" here, but that doesn't really answer the question.

The issue here is that CUE wants concrete values for expressions, treats optional fields as non existent, and regular fields as required. So in this case, x is marked as "incomplete", which is a kind of error that can be resolved by setting optional to a concrete string value. There is an upcoming proposal that slightly shifts this, making regular fields optional, which would allow ignoring this error (and then be more explicit about fields that are really required).

That doesn't change, though, that if one wants some default value for such…

Replies: 1 comment

Comment options

cueckoo
Jul 3, 2021
Collaborator Author

You must be logged in to vote
0 replies
Answer selected by cueckoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant