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

Error not surfaced when attempting to "dot" into type expression #12920

Closed
anthony-c-martin opened this issue Jan 5, 2024 · 0 comments · Fixed by #13047
Closed

Error not surfaced when attempting to "dot" into type expression #12920

anthony-c-martin opened this issue Jan 5, 2024 · 0 comments · Fixed by #13047
Assignees
Milestone

Comments

@anthony-c-martin
Copy link
Member

The following has no visible errors:

type test2 = {
  foo: {
    bar: string
  }
}

type test3 = test2.foo

However if I hover over test3, its type is correctly being reported as "error":
image

The same happens when trying to do something which is clearly invalid:

type test2 = {
  foo: {
    bar: string
  }
}

type test3 = test2.bar
@jeskew jeskew added this to the v0.25 milestone Jan 19, 2024
jeskew added a commit that referenced this issue Jan 26, 2024
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"}
``` 
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/13047)
asilverman pushed a commit that referenced this issue Jan 26, 2024
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants