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

typeexpr: Optional object attributes with defaults #549

Merged
merged 1 commit into from Sep 1, 2022

Conversation

alisdair
Copy link
Member

This commit extends the type expression package to add two new features:

  • In constraint mode, the optional(...) modifier can be used on object attributes to allow them to be omitted from input values to a type conversion process. Any such missing attributes will be replaced with a null value of the appropriate type upon conversion.
  • In the new defaults mode, the optional(...) modifier takes a second argument, which accepts a default value of an appropriate type. These defaults are returned alongside the type constraint, and may be applied prior to type conversion through the new Defaults.Apply() method.

This change is upstreamed from Terraform, where optional object attributes have been available for some time. The defaults functionality is new and due to be released with Terraform 1.3.

This commit extends the type expression package to add two new features:

- In constraint mode, the `optional(...)` modifier can be used on object
  attributes to allow them to be omitted from input values to a type
  conversion process. Any such missing attributes will be replaced with
  a `null` value of the appropriate type upon conversion.
- In the new defaults mode, the `optional(...)` modifier takes a second
  argument, which accepts a default value of an appropriate type. These
  defaults are returned alongside the type constraint, and may be
  applied prior to type conversion through the new `Defaults.Apply()`
  method.

This change is upstreamed from Terraform, where optional object
attributes have been available for some time. The defaults functionality
is new and due to be released with Terraform 1.3.
@alisdair alisdair requested a review from a team August 23, 2022 13:55
@alisdair alisdair self-assigned this Aug 23, 2022
Copy link
Member

@kmoe kmoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@alisdair alisdair merged commit 75d5692 into main Sep 1, 2022
@alisdair alisdair deleted the typeexpr-optional-defaults branch September 1, 2022 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants