Spreads and References
References¶
A reference points to a named VDL symbol.
References appear in several places:
- field types
- spreads
- constant values
- annotation arguments
Type References¶
Fields can reference declared types.
Fields can also reference enums.
Constant References¶
Constants can reference other constants by name.
Enum Member References¶
Use EnumName.MemberName to reference an enum member in literal values.
Type Spreads¶
Type spreads copy fields from another object type.
type AuditFields {
createdAt datetime
updatedAt datetime
}
type Article {
...AuditFields
id string
title string
}
After analysis, plugins see Article as if it had all fields directly.
Only object types can be spread into object types.
Invalid:
Inline Object Spreads¶
Inline objects can also spread object types.
type Money {
amount int
currency string
}
type Order {
id string
payment {
...Money
provider string
}
}
Field Conflicts¶
Spreads cannot introduce a field that already exists in the same object.
Invalid:
Rename one field or avoid the spread.
Enum Spreads¶
Enum spreads copy members from another enum.
enum StandardRole {
Viewer = "viewer"
Editor = "editor"
}
enum ProjectRole {
...StandardRole
Owner = "owner"
}
Enum spreads must reference enums, not enum members.
Invalid:
Object Literal Spreads¶
Object literals can spread constant objects.
const baseConfig = {
retries 3
timeoutMs 5000
}
const productionConfig = {
...baseConfig
timeoutMs 10000
}
Only object constants can be used this way.
Spread Cycles¶
Spreads cannot form cycles.
Invalid:
Keep spread hierarchies simple and acyclic.
Name Forms¶
VDL supports two reference forms:
| Form | Used for |
|---|---|
Name |
Types, constants, spreads |
Name.Member |
Enum member references in literal expressions |
Spreads must use Name, not Name.Member.