Skip to content

Commit 22fd29a

Browse files
committed
incorporate Anthony's comments
1 parent f5e5024 commit 22fd29a

File tree

1 file changed

+59
-7
lines changed

1 file changed

+59
-7
lines changed

articles/azure-resource-manager/bicep/data-types.md

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,24 @@ param exampleInt int = 1
104104

105105
In Bicep, integers are 64-bit integers. When passed as inline parameters, the range of values may be limited by the SDK or command-line tool you use for deployment. For example, when using PowerShell to deploy a Bicep, integer types can range from -2147483648 to 2147483647. To avoid this limitation, specify large integer values in a [parameter file](parameter-files.md). Resource types apply their own limits for integer properties.
106106

107-
You can use an integer as a specific integer type. In the following example, the first line is valid and defines an integer type with the value 1. The second line, however, results in a BCP033 error - Expected a value of type "2" but the provided value is of type "1".
107+
Bicep supports integer literal type which refers to a specific value that is an exact integer. In the following example, `1` is an integer literal type, `foo` can only be assigned the value `1` and no other value.
108108

109109
```bicep
110110
output foo 1 = 1
111-
output bar 2 = 1
112111
```
113112

114-
The following example, shows using specific integer types with a [union type](#union-types):
113+
An integer literal type can either be declared inline, as shown in the preceeding example, or in a [`type` statement](./user-defined-data-types.md).
114+
115+
```bicep
116+
type oneType = 1
117+
118+
output foo oneType = 1
119+
output bar oneType = 2
120+
```
121+
122+
In the preceeding example, assigning `2` to `bar` will result in results in a [BCP033](./bicep-error-bcp033.md) error - _Expected a value of type "1" but the provided value is of type "2"_.
123+
124+
The following example, shows using integer literal type with [union type](#union-types):
115125

116126
```bicep
117127
output bar 1 | 2 | 3 = 3
@@ -232,6 +242,32 @@ The following table lists the set of reserved characters that must be escaped by
232242
var myVar = 'what\'s up?'
233243
```
234244

245+
Bicep supports string literal type which refers to a specific string value. In the following example, `red` is a string literal type, `redColor` can only be assigned the value `red` and no other value.
246+
247+
```bicep
248+
output redColor 'red' = 'red'
249+
```
250+
251+
An string literal type can either be declared inline, as shown in the preceeding example, or in a [`type` statement](./user-defined-data-types.md).
252+
253+
```bicep
254+
type redColor = 'red'
255+
256+
output colorRed redColor = 'red'
257+
output colorBlue redColor = 'blue'
258+
```
259+
260+
In the preceeding example, assigning `blue` to `colorBlue` will result in results in a [BCP033](./bicep-error-bcp033.md) error - _Expected a value of type "'red'" but the provided value is of type "'blue'"_.
261+
262+
The following example, shows using string literal type with [union type](#union-types):
263+
264+
```bicep
265+
type direction = 'north' | 'south' | 'east' | 'west'
266+
267+
output west direction = 'west'
268+
output northWest direction = 'northwest'
269+
```
270+
235271
All strings in Bicep support interpolation. To inject an expression, surround it by `${` and `}`. Expressions that are referenced can't span multiple lines.
236272

237273
```bicep
@@ -283,14 +319,30 @@ is ${blocked}'''
283319

284320
## Union types
285321

286-
In Bicep, a union type represents one of several specified values within the same data type.
322+
In Bicep, a union type allows the creation of a combined type consisting of a set of sub-types. An assignment is valid if any of the individual sub-type assignments are permitted. The `|` character separates individual sub-types using an `or` condition. For example, the syntax `'a' | 'b'` means that a valid assignment could be either `'a'` or `'b'`.
287323

288324
```bicep
289-
output color 'Red' | 'Blue' | 'White' = 'White'
290-
output foo 'true' | 'false' = 'false'
291-
output bar 1 | 2 | 3 = 3
325+
type color = 'Red' | 'Blue' | 'White'
326+
type trueOrFalse = 'true' | 'false'
327+
type permittedIntegers = 1 | 2 | 3
292328
```
293329

330+
Any type expression can be used as a sub-type in a union type declaration (between `|` characters). For example, the following examples are all valid:
331+
332+
```bicep
333+
type foo = 1 | 2
334+
type bar = foo | 3
335+
type baz = bar | (4 | 5) | 6
336+
```
337+
338+
There are some limitations with union type.
339+
340+
* Union types must be reduceable to a single ARM type. The following definition is in valid:
341+
342+
```bicep
343+
type foo = 'a' | 1
344+
```
345+
294346
The union type syntax can also be used in [user-defined data types](./user-defined-data-types.md).
295347

296348
## Secure strings and objects

0 commit comments

Comments
 (0)