Skip to content

Latest commit

 

History

History
44 lines (30 loc) · 1.61 KB

operator-null-forgiving.md

File metadata and controls

44 lines (30 loc) · 1.61 KB
title description ms.topic ms.custom ms.date
Bicep null-forgiving operator
Describes Bicep null-forgiving operator.
reference
devx-track-bicep
05/04/2023

Bicep null-forgiving operator

The unary postfix ! operator is the null-forgiving, or null-suppression, operator. It's used to suppress all nullable warnings for the preceding expression. The null-forgiving operator has no effect at run time. It only affects the compiler's static flow analysis by changing the null state of the expression. At run time, expression x! evaluates to the result of the underlying expression x.

Null-forgiving

expression!

The null-forgiving operator ensures that a value isn't null, thereby changing the assigned type of the value from null | <type> to <type>. The following example fails the design time validation:

param inputString string

output outString string = first(skip(split(input, '/'), 1))

The warning message is:

Expected a value of type "string" but the provided value is of type "null | string".

To solve the problem, use the null-forgiving operator:

param inputString string

output outString string = first(skip(split(input, '/'), 1))!

Next steps