Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This diagnostic occurs when the compiler expects a value of one type but you provide something of a different type or null.
Description
Expected a value of type <expected-type> but the provided value is of type <actual-type> | null".
Level
Warning
Solutions
Use the expected type. If you're certain the value will never be null, use the null-forgiving operator to tell the compiler it's safe.
Examples
The following example raises the diagnostic because first(accounts) is possibly null if the array could be empty:
param storageCount int
param location string = resourceGroup().location
resource accounts 'Microsoft.Storage/storageAccounts@2023-05-01' = [for i in range(0, storageCount):{
name: 'sa${i}'
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}]
output firstOne object = first(accounts)
You can fix the diagnostic by using the null-forgiving operator:
param storageCount int
param location string = resourceGroup().location
resource accounts 'Microsoft.Storage/storageAccounts@2023-05-01' = [for i in range(0, storageCount):{
name: 'sa${i}'
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}]
output firstOne object = first(accounts)!
Next steps
For more information about Bicep diagnostics, see Bicep core diagnostics.