Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partially addresses #10121 This PR adds compile-time imports for user-defined types. This feature is only available under a flag and must be enabled with a bicepconfig.json file that looks like this: ```json { "experimentalFeaturesEnabled": { "compileTimeImports": true, "userDefinedTypes": true } } ``` With the feature enabled, the `import` keyword can be used to move user-defined types across templates. For example, given the following template saved as `mod.bicep`: ```bicep @export() type foo = string @export() type bar = int ``` The `foo` and `bar` type symbols can be imported into another template either individually by name using "symbols list" syntax: ```bicep import {foo, bar} from 'mod.bicep' ``` or with "wildcard" syntax (which is less efficient but more fun to say): ```bicep import * as myImports from 'mod.bicep' ``` With the "symbols" list syntax, you can import a subset of the target template's exported symbols and rename/alias them at will: ```bicep import {foo} from 'mod.bicep' // <-- Omits bar from the compiled template import {bar} from 'mod.bicep' // <-- Omits foo from the compiled template import { foo as fizz bar as buzz } from 'mod.bicep' // <-- Aliases both foo and bar ``` You can also mix and match syntaxes. Symbols will be imported at most once: ```bicep import {foo} from 'mod.bicep' import * as baz from 'mod.bicep' ``` Imported types can be used anywhere a user-defined type might be (i.e., within the type clauses of `type`, `param`, and `output` statements). Only types that bear the `@export()` decorator can be imported. As of this PR, this decorator can only be used on `type` statements. ###### Microsoft Reviewers: codeflow:open?pullrequest=https://github.com/Azure/bicep/pull/11298&drop=dogfoodAlpha
- Loading branch information