-
Notifications
You must be signed in to change notification settings - Fork 760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide support for typed variables + Bicep doesn't validate the type of variables in a loop #11891
Comments
I agree with you that type hints on variables would improve the experience here. I think Bicep is doing the right thing by showing diagnostics on the variable reference rather than the variable definition, since variables may be used in multiple places. If Bicep gave you a way to provide a type for a variable, though, diagnostics would get attached to the declaration itself: var database1Configuration: sqlDatabaseConfigurationType = {
name: 'Database1'
containerConfigurations: [
{
name: 'Collection1'
indexngPolicy: defaultIndexingPolicy // this line would have a diagnostic since it doesn't match the declared type due to a property name typo
}
{ // this line and the next two would have a diagnostic since it doesn't match the declared type due to a missing property
name: 'Collection2'
}
]
} When using a loop, it looks like Bicep will fall back to an untyped type loopLocal_database = {
name: 'Collection1' | 'Collection2'
indexngPolicy: <inferred type of defaultIndexingPolicy>?
} |
@dekomissMSFT would you mind upvoting #9364 for typed variable support? We can use this issue to track the loop-local variable type inference gap. |
Is your feature request related to a problem? Please describe.
I am using Bicep v0.21.1 and have enabled "compileTimeImports": true in my bicepconfig.json (though I don't think this is necessary to repro)
I have a Bicep module where I want to pass in an object and use that to create various resources. I defined a custom type for the object and added it as a parameter to the module. In a parent template, I define the object in a variable and pass it to the module. I would like for Bicep to show me where properties are missing in the variable rather than where I reference the variable.
Example
CosmosDbDatabaseWithContainers.module.bicep
CosmosDbAccount.bicep
Describe the solution you'd like
Problem 1:
The line at the end that reads "sqlDatabaseConfiguration: database1Configuration" shows an error indicating the typo and missing property:
It would be ideal to see these errors show up on the lines where the typo/missing property actually are within the variable, since for a large object that references other variables it could be difficult to spot where the issue is.
Problem 2:
If I change "sqlDatabaseConfiguration: database1Configuration" to "sqlDatabaseConfiguration: database" to use the value from the loop, then Bicep doesn't display any error at all. I would like to see the same error that I see in the above screenshot.
The text was updated successfully, but these errors were encountered: