Azure / Azure/bicep

Nullable properties should receive implicit null value when value is not provided

Open
#14,664 1 comment 3 reactions 0 assignees View on GitHub
Needs: Upvote
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
0.29.47

**Describe the bug**
Custom types do not implicitly assign null to nullable values that are not provided. For example, in a custom type with a nullable property, you should be able to use the dot operator for that property and receive null when that property is not explicitly defined. Instead, you receive an exception:

```
The template output 'implicitlyDefinedNullValue' is not valid: The language expression property 'value' doesn't exist, available properties are ''..
```

**To Reproduce**
```
type MySimpleType = {
value: string?
}

// EXPLICIT PROPERTY DEFINITION

param explicitlyDefinedObject MySimpleType = {
value: 'hello world'
}

// Output: 'hello world'
output explicitlyDefinedValue string? = explicitlyDefinedObject.value

// EXPLICIT NULL PROPERTY DEFINITION

param objectWithExplicitNull MySimpleType = {
value: null
}

// Output: empty string
output explicitlyDefinedNullValue string? = objectWithExplicitNull.value

// IMPLICT NULL PROPERTY DEFINITION

param objectWithImplicitNull MySimpleType = {
}

// Output: Error
// Desired output: empty string
output implicitlyDefinedNullValue string? = objectWithImplicitNull.value
```

**Additional context**

Without this feature, you must manually check that all nullable properties contain a value before using a dot operator:

```
output implicitlyDefinedNullValueThatDoesNotThrow string? = contains(objectWithImplicitNull, 'value') ? objectWithImplicitNull.value : null
```

This is cumbersome; it would be much easier if types assumed null for nullable properties where the value is not explicitly defined.

If throwing an error in this scenario is the desired functionality of nullable values, the type system / compiler should probably block you from creating objects that don't define all of the properties. For example, the compiler should complain when you create an object like this since it essentially makes the type no longer safe.

```
param objectWithImplicitNull MySimpleType = {
}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue using the custom type and parameter examples in the report, then compare explicit, explicit-null, and omitted nullable properties. The issue names no source files or tests, so first locate the compiler or type-system entry point handling nullable custom-type property access. Done means omitted nullable properties yield null through the dot operator, or the compiler clearly rejects the incomplete object.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.