Skip to content

Commit 934a03b

Browse files
committed
tagged union type declaration
1 parent 970a517 commit 934a03b

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: User-defined types in Bicep
33
description: Describes how to define and use user-defined data types in Bicep.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 09/20/2023
6+
ms.date: 09/22/2023
77
---
88

99
# User-defined data types in Bicep
@@ -217,6 +217,37 @@ resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
217217
}
218218
```
219219

220+
## Declare tagged union type
221+
222+
To declare a custom tagged union data type within a Bicep file, you can place a discriminator decorator above a user-defined type declartion. [Bicep version 0.21.1 or newer](./install.md) is required to use this decorator. The syntax is:
223+
224+
```bicep
225+
@discriminator('<propertyName>')
226+
```
227+
228+
The discriminator decorator takes a single parameter, which represents a shared property name among all union members. This property name must be a required string literal on all members and is case-sensitive. The values of the discriminated property on the union members must be unique in a case-insensitive manner.
229+
230+
Here is an example:
231+
232+
```bicep
233+
type FooConfig = {
234+
type: 'foo'
235+
value: int
236+
}
237+
238+
type BarConfig = {
239+
type: 'bar'
240+
value: bool
241+
}
242+
243+
@discriminator('type')
244+
type ServiceConfig = FooConfig | BarConfig | { type: 'baz', *: string }
245+
246+
param serviceConfig ServiceConfig = { type: 'bar', value: true }
247+
248+
output config object = serviceConfig
249+
```
250+
220251
## Import types between Bicep files (Preview)
221252

222253
[Bicep version 0.21.1 or newer](./install.md) is required to use this compile-time import feature. The experimental flag `compileTimeImports` must be enabled from the [Bicep config file](./bicep-config.md#enable-experimental-features).

0 commit comments

Comments
 (0)