Skip to content
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

Simple array types in parameters and outputs #114

Closed
majastrz opened this issue Jul 29, 2020 · 2 comments
Closed

Simple array types in parameters and outputs #114

majastrz opened this issue Jul 29, 2020 · 2 comments
Labels
syntax Related to language syntax

Comments

@majastrz
Copy link
Member

Current

Current syntax for parameters and outputs allows the user to specify array as the type. This type is equivalent to any[] type in TS (each item can be of any other type and each item can be of a different type).

Proposal

Allow the user to declare the item type for arrays of bool, string, and int types.

Non-Goals

There exists a separate problem of user-defined object types. This proposal does not attempt to address that at all.

Examples

Simple one-level arrays could look like this:

parameter myStringArray string[]
parameter myIntArray int[]
output myBoolArray bool[] = <expression>

Nesting would be allowed and would look like the following:

parameter myArrayOfStringArrays string[][]
parameter myArrayOfIntArrays int[][]
output myArrayOfBoolArrays bool[][] = <expression>

Compiled JSON

These narrower array types do not exist in JSON. We would compile them all to array type until JSON supports those types. Until then, there would be no runtime checking for this. When referencing bicep modules, bicep would be able to use the enhanced type information to produce better/more errors.

In the native module case (referencing a compiled or hand-written JSON template), bicep would have to fall back to any[] type unless the extra metadata needed can be embedded in the JSON.

@PietervdWerk
Copy link

This would indeed increase validation possibilities like catching a simple error like below. The array is a one-dimensional array, while the module tries to access the second dimension and would therefore fail at deployment.

param environments string[]

module KeyVaults '../any/key-vault.bicep' = [for (environment, i) in environments: {
  name: 'key-vault-${environment[i]}'
  params: {
    ProductName: 'ProductName'
    Environment: environment[i]
  }
}]

@anthony-c-martin
Copy link
Member

Closing as this is covered by the "user defined types" work.

@ghost ghost locked as resolved and limited conversation to collaborators May 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
syntax Related to language syntax
Projects
None yet
Development

No branches or pull requests

4 participants