-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow use of type properties as type expressions (#13047)
Resolves #12920 Resolves #9229 This PR allows elements or properties of types to be used as standalone type expressions. This feature is compatible with both resource-derived types and compile-time imports, as shown in the following example: types.bicep ```bicep @export() type myObject = { quux: int saSku: resource<'Microsoft.Storage/storageAccounts@2022-09-01'>.sku } ``` main.bicep ```bicep import * as types from 'types.bicep' type test = { baz: types.myObject } type test2 = { foo: { bar: test } } type test3 = test2.foo.bar.baz.quux // ^^ compiles to {"$ref": "#/definitions/_1.myObject/properties/quux"} type test4 = test2.foo.bar.baz.saSku.name // ^^ compiles to: // { // "type": "string", // "metadata": { // "__bicep_resource_derived_type!": "Microsoft.Storage/storageAccounts@2022-09-01#properties/sku/properties/name" // } // } ``` Accessing the following element kinds is supported: * Properties may be dereferenced via dot notation * Tuple items may be dereferenced via array index * An object's additional properties type declaration may be dereferenced via a special `.*` syntax * A typed array's element type declaration may be dereferenced via a special `[*]` syntax For example: ```bicep type anObject = { property: int *: string } type strings = string[] type tuple = [int, string] param propertyDeref anObject.property = 10 // type compiles to {"$ref": "#/definitions/anObject/properties/property"} param additionalPropertiesDeref anObject.* = 'foo' // type compiles to {"$ref": "#/definitions/anObject/additionalProperties"} param elementDeref strings[*] = 'bar' // type compiles to {"$ref": "#/definitions/strings/items"} param itemDeref tuple[1] = 'baz' // type compiles to {"$ref": "#/definitions/tuple/prefixItems/1"} ``` CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/13047)
- Loading branch information
Showing
103 changed files
with
4,687 additions
and
1,466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.