Skip to content

Commit b2871ac

Browse files
authored
Merge pull request #309112 from mumian/1205-bcp293
Document BCP293
2 parents 0798ce4 + dff23db commit b2871ac

4 files changed

Lines changed: 69 additions & 2 deletions

File tree

articles/azure-resource-manager/bicep/bicep-core-diagnostics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ If you need more information about a particular diagnostic code, select the **Fe
285285
| <a id='BCP290' />[BCP290](./diagnostics/bcp290.md) | Error | Expected a parameter or type declaration after the decorator. |
286286
| <a id='BCP291' />BCP291 | Error | Expected a parameter or output declaration after the decorator. |
287287
| <a id='BCP292' />[BCP292](./diagnostics/bcp292.md) | Error | Expected a parameter, output, or type declaration after the decorator. |
288-
| <a id='BCP293' />BCP293 | Error | All members of a union type declaration must be literal values. |
288+
| <a id='BCP293' />[BCP293](./diagnostics/bcp293.md) | Error | All members of a union type declaration must be literal values. |
289289
| <a id='BCP294' />[BCP294](./diagnostics/bcp294.md) | Error | Type unions must be reducible to a single ARM type (such as `string`, `int`, or `bool`). |
290290
| <a id='BCP295' />BCP295 | Error | The `{decoratorName}` decorator may not be used on targets of a union or literal type. The allowed values for this parameter or type definition will be derived from the union or literal type automatically. |
291291
| <a id='BCP296' />BCP296 | Error | Property names on types must be compile-time constant values. |
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: BCP293
3+
description: All members of a union type declaration must be literal values.
4+
ms.topic: reference
5+
ms.custom: devx-track-bicep
6+
ms.date: 12/05/2025
7+
---
8+
9+
# Bicep diagnostic code - BCP293
10+
11+
This diagnostic occurs when you declare a union type with members that aren't literal values.
12+
13+
## Description
14+
15+
All members of a union type declaration must be literal values.
16+
17+
## Level
18+
19+
Error
20+
21+
## Solution
22+
23+
Ensure that all members of a union type declaration are literal values. For more information, see [User-defined data types](../user-defined-data-types.md).
24+
25+
## Examples
26+
27+
The following example raises the diagnostic because the intent behind the following code is to restrict the input to specific environments ('dev', 'test', 'prod') while also trying to allow any other string value. Bicep's type system doesn't permit this mix in a union.
28+
29+
```bicep
30+
type EnvironmentType = 'dev' | 'test' | 'prod' | string
31+
```
32+
33+
If the goal is to strictly enforce the three allowed values and fail compilation otherwise, remove the generic string type.
34+
35+
```bicep
36+
type EnvironmentType = 'dev' | 'test' | 'prod'
37+
```
38+
39+
If the goal is to allow any string value and the predefined list is just a suggestion, use the generic `string` type directly and remove the union altogether.
40+
41+
```bicep
42+
type EnvironmentType = string
43+
```
44+
45+
The following example is another example where mixing literals with objects containing generic primitives isn't allowed:
46+
47+
```bicep
48+
type oneOfSeveralObjects = {foo: 'bar', bar: string} | {fizz: 'buzz'} | {snap: 'crackle'}
49+
```
50+
51+
To fix the problem, all members must be of the same type category. Since the intent here is a union of complex types, the simplest fix is to ensure all properties that are intended to be constants are defined as string literals throughout the union.
52+
53+
```bicep
54+
type oneOfSeveralObjects = {foo: 'bar', bar: 'baz'} | {fizz: 'buzz'} | {snap: 'crackle'}
55+
```
56+
57+
## Next steps
58+
59+
For more information about Bicep diagnostics, see [Bicep core diagnostics](../bicep-core-diagnostics.md).

articles/azure-resource-manager/bicep/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ items:
739739
href: diagnostics/bcp290.md
740740
- name: BCP292
741741
href: diagnostics/bcp292.md
742+
- name: BCP293
743+
href: diagnostics/bcp293.md
742744
- name: BCP294
743745
href: diagnostics/bcp294.md
744746
- name: BCP302

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,13 @@ The valid type expressions include:
143143
- Unions can include any number of literal-typed expressions. Union types are translated into the [allowed-value constraint](./parameters.md#use-decorators) in Bicep, so only literals are permitted as members.
144144
145145
```bicep
146-
type oneOfSeveralObjects = {foo: 'bar'} | {fizz: 'buzz'} | {snap: 'crackle'}
146+
type oneOfSeveralObjects = {
147+
foo: 'bar'
148+
} | {
149+
fizz: 'buzz'
150+
} | {
151+
snap: 'crackle'
152+
}
147153
type mixedTypeArray = ('fizz' | 42 | {an: 'object'} | null)[]
148154
```
149155

0 commit comments

Comments
 (0)