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
+25-25Lines changed: 25 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: User-defined types in Bicep
3
-
description: Describes how to define and use user-defined data types in Bicep.
3
+
description: This article describes how to define and use user-defined data types in Bicep.
4
4
ms.topic: conceptual
5
5
ms.custom: devx-track-bicep
6
6
ms.date: 08/20/2024
@@ -14,14 +14,14 @@ Learn how to create user-defined data types in Bicep. For system-defined data ty
14
14
15
15
## Define types
16
16
17
-
You can use the `type` statement to create user-defined data types. In addition, you can also use type expressions in some places to define custom types.
17
+
You can use the `type` statement to create user-defined data types. You can also use type expressions in some places to define custom types.
18
18
19
19
```bicep
20
20
@<decorator>(<argument>)
21
21
type <user-defined-data-type-name> = <type-expression>
22
22
```
23
23
24
-
The [`@allowed`](./parameters.md#use-decorators) decorator is only permitted on [`param` statements](./parameters.md). To declare a type with a set of predefined values in a `type`, use [union type syntax](./data-types.md#union-types).
24
+
The [`@allowed`](./parameters.md#use-decorators) decorator is permitted only on [`param` statements](./parameters.md). To declare a type with a set of predefined values in a `type`, use [union type syntax](./data-types.md#union-types).
25
25
26
26
The valid type expressions include:
27
27
@@ -35,7 +35,7 @@ The valid type expressions include:
35
35
type myOtherStringType = myStringType
36
36
```
37
37
38
-
- Primitive literals, including strings, integers, and booleans, are valid type expressions. For example:
38
+
- Primitive literals, including strings, integers, and Booleans, are valid type expressions. For example:
39
39
40
40
```bicep
41
41
// a string type with three allowed values.
@@ -71,7 +71,7 @@ The valid type expressions include:
71
71
}
72
72
```
73
73
74
-
Each property in an object consists of a key and a value, separated by a colon `:`. The key can be any string, with nonidentifier values enclosed in quotes, and the value can be any type of expression.
74
+
Each property in an object consists of a key and a value separated by a colon `:`. The key can be any string, with nonidentifier values enclosed in quotation marks. The value can be any type of expression.
75
75
76
76
Properties are required unless they have an optionality marker `?` after the property value. For example, the `sku` property in the following example is optional:
77
77
@@ -82,7 +82,7 @@ The valid type expressions include:
82
82
}
83
83
```
84
84
85
-
Decorators can be used on properties. `*` can be used to make all values require a constraint. Additional properties can still be defined when using `*`. This example creates an object that requires a key of type `int` named *id*, and that all other entries in the object must be a string value at least 10 characters long.
85
+
You can use decorators on properties. You can use an asterisk (`*`) to make all values require a constraint. You can define more properties by using `*`. This example creates an object that requires a key of type `int` named `id`. All other entries in the object must be a string value at least 10 characters long.
86
86
87
87
```bicep
88
88
type obj = {
@@ -105,9 +105,9 @@ The valid type expressions include:
105
105
}
106
106
```
107
107
108
-
**Recursion**
108
+
### Recursion
109
109
110
-
Object types can 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:
110
+
Object types can use direct or indirect recursion if at least the 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:
111
111
112
112
```bicep
113
113
type myObjectType = {
@@ -116,7 +116,7 @@ The valid type expressions include:
116
116
}
117
117
```
118
118
119
-
But the following type definition wouldn't be valid because none of `level1`, `level2`, `level3`, `level4`, or `level5` is optional.
119
+
The following type definition wouldn't be valid because none of `level1`, `level2`, `level3`, `level4`, or `level5` is optional.
120
120
121
121
```bicep
122
122
type invalidRecursiveObjectType = {
@@ -132,7 +132,7 @@ The valid type expressions include:
132
132
}
133
133
```
134
134
135
-
- [Bicep unary operators](./operators.md) can be used with integer and boolean literals or references to integer or boolean literal-typed symbols:
135
+
- You can use [Bicep unary operators](./operators.md) with integer and Boolean literals or references to integer or Boolean literal-typed symbols:
136
136
137
137
```bicep
138
138
type negativeIntLiteral = -10
@@ -149,7 +149,7 @@ The valid type expressions include:
In addition to be used in the `type` statement, type expressions can also be used in these places for creating user-defined data types:
152
+
You can use type expressions in the `type` statement, and you can also use type expressions to create user-defined data types, as shown in the following places:
153
153
154
154
- As the type clause of a `param` statement. For example:
By using user-defined data types, it can look like:
207
+
With user-defined data types, it can look like:
208
208
209
209
```bicep
210
210
param location string = resourceGroup().location
@@ -239,21 +239,21 @@ Decorators are written in the format `@expression` and are placed above the decl
239
239
|[export](#export)| all | none | Indicates that the user-defined data type is available for import by another Bicep file. |
240
240
|[maxLength](#length-constraints)| array, string | int | The maximum length for string and array data types. The value is inclusive. |
241
241
|[maxValue](#integer-constraints)| int | int | The maximum value for the integer data types. This value is inclusive. |
242
-
|[metadata](#metadata)| all | object | Custom properties to apply to the data types. Can include a description property that is equivalent to the description decorator. |
242
+
|[metadata](#metadata)| all | object | Custom properties to apply to the data types. Can include a description property that's equivalent to the description decorator. |
243
243
|[minLength](#length-constraints)| array, string | int | The minimum length for string and array data types. The value is inclusive. |
244
244
|[minValue](#integer-constraints)| int | int | The minimum value for the integer data types. This value is inclusive. |
245
-
|[sealed](#sealed)| object | none | Elevate [BCP089](./diagnostics/bcp089.md) from a warning to an error when a property name of a use-define data type is likely a typo. For more information, see [Elevate error level](#elevate-error-level).|
245
+
|[sealed](#sealed)| object | none | Elevate [BCP089](./diagnostics/bcp089.md) from a warning to an error when a property name of a user-defined data type is likely a typo. For more information, see [Elevate error level](#elevate-error-level).|
246
246
|[secure](#secure-types)| string, object | none | Marks the types as secure. The value for a secure type isn't saved to the deployment history and isn't logged. For more information, see [Secure strings and objects](data-types.md#secure-strings-and-objects). |
247
247
248
-
Decorators are in the [sys namespace](bicep-functions.md#namespaces-for-functions). If you need to differentiate a decorator from another item with the same name, preface the decorator with `sys`. For example, if your Bicep file includes a variable named `description`, you must add the sys namespace when using the **description** decorator.
248
+
Decorators are in the [sys namespace](bicep-functions.md#namespaces-for-functions). If you need to differentiate a decorator from another item with the same name, preface the decorator with `sys`. For example, if your Bicep file includes a variable named `description`, you must add the `sys` namespace when you use the `description` decorator.
249
249
250
250
### Discriminator
251
251
252
252
See [Tagged union data type](#tagged-union-data-type).
253
253
254
254
### Description
255
255
256
-
Add a description to the user-defined data type. Decorators can be used on properties. For example:
256
+
Add a description to the user-defined data type. You can use decorators on properties. For example:
257
257
258
258
```bicep
259
259
@description('Define a new object type.')
@@ -267,7 +267,7 @@ type obj = {
267
267
}
268
268
```
269
269
270
-
Markdown-formatted text can be used for the description text.
270
+
You can use Markdown-formatted text for the description text.
271
271
272
272
### Export
273
273
@@ -287,7 +287,7 @@ type month int
287
287
288
288
You can specify minimum and maximum lengths for string and array types. You can set one or both constraints. For strings, the length indicates the number of characters. For arrays, the length indicates the number of items in the array.
289
289
290
-
The following example declares two type. One type is for a storage account name that must have 3-24 characters. The other type is an array that must have from 1-5 items.
290
+
The following example declares two types. One type is for a storage account name that must have 3 to 24 characters. The other type is an array that must have from one to five items.
291
291
292
292
```bicep
293
293
@minLength(3)
@@ -314,15 +314,15 @@ You might use this decorator to track information about the data type that doesn
314
314
type settings object
315
315
```
316
316
317
-
When you provide a `@metadata()` decorator with a property that conflicts with another decorator, that decorator always takes precedence over anything in the `@metadata()` decorator. So, the conflicting property within the `@metadata()` value is redundant and will be replaced. For more information, see [No conflicting metadata](./linter-rule-no-conflicting-metadata.md).
317
+
When you provide a `@metadata()` decorator with a property that conflicts with another decorator, that decorator always takes precedence over anything in the `@metadata()` decorator. So, the conflicting property within the `@metadata()` value is redundant and is replaced. For more information, see [No conflicting metadata](./linter-rule-no-conflicting-metadata.md).
318
318
319
319
### Sealed
320
320
321
321
See [Elevate error level](#elevate-error-level).
322
322
323
323
### Secure types
324
324
325
-
You can mark string or object user-defined data type as secure. The value of a secure type isn't saved to the deployment history and isn't logged.
325
+
You can mark a string or object user-defined data type as secure. The value of a secure type isn't saved to the deployment history and isn't logged.
326
326
327
327
```bicep
328
328
@secure()
@@ -334,7 +334,7 @@ type demoSecretObject object
334
334
335
335
## Elevate error level
336
336
337
-
By default, declaring an object type in Bicep allows it to accept additional properties of any type. For example, the following Bicep is valid but raises a warning of [BCP089] -`The property "otionalProperty" is not allowed on objects of type "{ property: string, optionalProperty: null | string }". Did you mean "optionalProperty"?`:
337
+
By default, declaring an object type in Bicep allows it to accept more properties of any type. For example, the following Bicep is valid but raises a warning of [BCP089]:`The property "otionalProperty" is not allowed on objects of type "{ property: string, optionalProperty: null | string }". Did you mean "optionalProperty"?`:
338
338
339
339
```bicep
340
340
type anObject = {
@@ -348,7 +348,7 @@ param aParameter anObject = {
348
348
}
349
349
```
350
350
351
-
The warning informs you that the *anObject* type doesn't include a property named *otionalProperty*. While no errors occur during deployment, the Bicep compiler assumes *otionalProperty* is a typo, that you intended to use *optionalProperty* but misspelled it, and alert you to the inconsistency.
351
+
The warning informs you that the `anObject` type doesn't include a property named `otionalProperty`. Although no errors occur during deployment, the Bicep compiler assumes that `otionalProperty` is a typo and that you intended to use `optionalProperty` but misspelled it. Bicep alerts you to the inconsistency.
352
352
353
353
To escalate these warnings to errors, apply the `@sealed()` decorator to the object type:
354
354
@@ -375,7 +375,7 @@ param aParameter anObject = {
375
375
}
376
376
```
377
377
378
-
The ARM deployment engine also checks sealed types for additional properties. Providing any extra properties for sealed parameters results in a validation error, causing the deployment to fail. For example:
378
+
The Azure Resource Manager deployment engine also checks sealed types for other properties. Providing any extra properties for sealed parameters results in a validation error, which causes the deployment to fail. For example:
0 commit comments