当编译器预期某一类型的值,但你提供了不同类型的值或空值时,就会发生这种诊断。
Description
期望值类型为 <预期类型> ,但所提供的值类型为 <actud-type> | null“。
级别
Warning
解决方案
使用预期的类型。 如果确定该值永远不会为 null,请使用 null 表示运算符 告知编译器它是安全的。
Examples
以下示例提出了诊断问题,因为 first(accounts) 如果数组可能为空,则可能是空的:
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)
可以使用 null 放弃运算符修复诊断:
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)!
后续步骤
有关 Bicep 诊断的详细信息,请参阅 Bicep 核心诊断。