Type grammar#
Type grammar describes primitive types, references, generics, optionals, arrays, maps, unions, intersections, and function types.
Source#
| Property | Value |
|---|---|
| Grammar file | packages/business/language/grammar/type.g4 |
| Grammar name | type |
| Grammar kind | parser |
| Imports | common, literal |
| Imported by | annotation, api, app, BusinessLanguage, class, entity, enum, errorHandling, form, function, interface, message, module, query, rule, service, struct, subscription, table, test, validation |
| Direct rule or token count | 46 |
How to use this page#
Read the examples first when authoring Business Language. Use the rule inventory when checking exact grammar coverage or when updating parser, lowering, editor, or documentation behavior.
Entry rules and syntax families#
Start with these rules when reading this grammar: typeDeclaration, typeExpression, intersectionType, conditionalType, postfixType, primaryType, builtinType, primitiveType, arrayType, customType.
- Declarations:
typeDeclaration - Expressions:
conditionalTypeExpression,intersectionTypeExpression,typeExpression,unionTypeExpression - Types:
arrayType,builtinType,conditionalType,customType,functionType,genericType,intersectionType,mappedType, and 5 more - Bodies:
constraintBody
Key grammar excerpts#
typeDeclaration#
typeDeclaration
: TYPE identifier (COLON typeExpression)? SEMICOLON # TypeAlias
| TYPE identifier OPEN_BRACE typeMemberList? CLOSE_BRACE # TypeObject
// @define @name_fields(identifier) @symbol(kind=global) @scope(level=2)
;typeExpression#
typeExpression
: intersectionType (PIPE_OP intersectionType)*
// @kind(type)
;intersectionType#
intersectionType
: conditionalType (AMP_OP conditionalType)*
;Complete rule and token inventory#
arraySuffix, arraySuffixList, arrayType, builtinType, conditionalType, conditionalTypeExpression, conditionalTypeNoNullable, constraintBody
customType, functionType, genericArgumentSuffix, genericParameter, genericParameterList, genericParameters, genericType, intersectionType
intersectionTypeExpression, intersectionTypeNoNullable, intersectionTypeTail, mappedType, nullableSuffix, postfixType, postfixTypeNoNullable, primaryType
primitiveType, referenceType, tupleType, typeArgumentList, typeArguments, typeConstraint, typeDeclaration, typeExpression
typeExpressionNoNullable, typeLiteralArgument, typeLiteralParameters, typeMember, typeMemberList, typeParameter, typeParameterListCore, typeParameters
typeSuffix, typeSuffixList, typeSuffixListNoNullable, typeSuffixNoNullable, unionTypeExpression, unionTypeTailExamples#
Optional and array types#
field Tags: string[];
field OptionalVendor: Vendor?;Generic map type#
field LocalizedText: map<string, string>;Alias and object types#
type ExternalPartyId: string | uuid;
type PostingPayload {
invoice_id: InvoiceId;
amount: money;
}Grouped, reference, tuple, and mapped aliases#
type IdentifierList: (string | uuid)[];
type InvoiceRef: ref<Invoice>;
type CoordinatePair: (decimal, decimal);
type LocalizedValues: { [K in LocaleKey]: string };Function type aliases#
type InvoicePredicate: (Invoice) -> bool;
type NowProvider: () -> datetime;Common authoring mistakes#
- Do not copy examples without checking the rule inventory for the exact grammar boundary.
- Do not add behavior that depends on missing configuration or undeclared user-facing errors.
Related guides#
- /language/types-literals/
- /language/expressions/
Authoring notes#
- Keep examples aligned with the grammar source, not with inferred syntax from another language.
- Use declared messages for user-facing failures, and fail closed when required configuration is absent.