Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Interpolation of Optional values #790

Answered by mpvl
kalexmills asked this question in Q&A
Discussion options

You must be logged in to vote

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 an expression, one needs to explicitly state this.

N…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by kalexmills
Comment options

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