Aliases provide a way to refer to a value by a different identifier.
They are declared using an equals sign (=
).
An alias is typically used to access a field in an outer scope that has been
made inaccessible, or shadowed.
Some of their other uses are also demonstrated in the example below.
Aliases are not members of a struct.
They do not appear in output, and can only be referenced within the scope in
which they are defined.
file.cue
// Alias A provides access to a top-level field
// with a name that is not a valid identifier.
A="a top level field": 1
// Alias B provides access to a dynamic field.
#b: "a dynamic field"
B=(#b): 2
a: A
b: B
// Alias C provides access to a field that's
// shadowed in c's innermost scope.
c: C={
field: value: 3
d: {
field: C.field.value
}
}
TERMINAL
$ cue export file.cue
{
"a top level field": 1,
"a": 1,
"b": 2,
"a dynamic field": 2,
"c": {
"field": {
"value": 3
},
"d": {
"field": 3
}
}
}
The CUE language specification defines the full list of positions where an alias can be declared.