You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/user-defined-data-types.md
+26-24Lines changed: 26 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,11 +9,11 @@ ms.date: 01/09/2023
9
9
10
10
Learn how to use user-defined data types in Bicep.
11
11
12
-
Bicep version 1.2 or newer is required. To install the latest versions, see [Install](./install.md).
12
+
[Bicep version 1.2 or newer](./install.md) is required to use this feature.
13
13
14
14
## Enable the preview feature
15
15
16
-
To enable this preview, modify your project's [bicepconfig.json file](./bicep-config.md) to include the following JSON:
16
+
To enable this preview, modify your project's [bicepconfig.json](./bicep-config.md) file to include the following JSON:
17
17
18
18
```json
19
19
{
@@ -25,36 +25,38 @@ To enable this preview, modify your project's [bicepconfig.json file](./bicep-co
25
25
26
26
## User-defined data type syntax
27
27
28
+
You can use the `type` statement to define user-defined data types. In addition, you can also use type expressions in some places to define custom types.
29
+
28
30
```bicep
29
31
Type <userDefinedDataTypeName> = <typeExpression>
30
32
```
31
33
32
-
Valid type expression include:
34
+
The valid type expressions include:
33
35
34
-
-Strings, integers, and booleans are valid data types to be used as type expressions.
36
+
-Symbolic references are identifiers that refer to an *ambient* type (like `string` or `int`) or a user-defined type symbol declared in a `type` statement:
35
37
36
38
```bicep
37
-
// a string type with three allowed values.
38
-
type myStringLiteral = 'bicep' | 'arm' | 'azure'
39
-
40
-
// an integer type with one allowed value
41
-
type myIntLiteral = 10
39
+
// Bicep data type reference
40
+
type myStringType = string
42
41
43
-
// an boolean type with one allowed value
44
-
type myBoolLiteral = true
42
+
// user-defined type reference
43
+
type myOtherStringType = myStringType
45
44
```
46
45
47
-
- Symbolic references of [Bicep data types](./data-types.md) or user-defined data types are valid type expressions.
46
+
- Primitive literals, including strings, integers, and booleans, are valid type expressions. For example:
48
47
49
48
```bicep
50
-
// Bicep data type reference
51
-
type myStringType = string
49
+
// a string type with three allowed values.
50
+
type myStringLiteralType = 'bicep' | 'arm' | 'azure'
52
51
53
-
// user-defined type reference
54
-
type myOtherStringType = myStringType
52
+
// an integer type with one allowed value
53
+
type myIntLiteralType = 10
54
+
55
+
// an boolean type with one allowed value
56
+
type myBoolLiteralType = true
55
57
```
56
58
57
-
- Array types can be declared by suffixing `[]` to any valid type expression.
59
+
- Array types can be declared by suffixing `[]` to any valid type expression:
@@ -90,19 +92,19 @@ Valid type expression include:
90
92
91
93
**Recursion**
92
94
93
-
Object types may use direct or indirect recursion so long as at least leg of the path to the recursion point is optional. For example, the myObject definition in the following example is valid because the directly recursive recursiveProp property is optional:
95
+
Object types may use direct or indirect recursion so long as at least leg of the path to the recursion point is optional. For example, the `myObjectType` definition in the following example is valid because the directly recursive `recursiveProp` property is optional:
94
96
95
97
```bicep
96
-
type myObject = {
98
+
type myObjectType = {
97
99
stringProp: string
98
-
recursiveProp?: myObject
100
+
recursiveProp?: myObjectType
99
101
}
100
102
```
101
103
102
-
But the following would not be valid because none of `level1`, `level2`, `level3`, `level4`, or `level5` is optional, there is no JSON object that would be able to fulfill this schema.
104
+
But the following would not be valid because none of `level1`, `level2`, `level3`, `level4`, or `level5` is optional.
0 commit comments