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

Remove undefined cases from inputs to all function #11048

Merged
merged 2 commits into from Oct 18, 2022

Conversation

danielrbradley
Copy link
Member

@danielrbradley danielrbradley commented Oct 17, 2022

Description

Using all currently looses type safety around the handling of input values which are possibly undefined. By adding the explicit undefined option to each argument, the undefined case outside the inputty type does not get captured.

By removing the explicit undefined cases, the undefined is captured by the generic parameter and correctly carried through to the output type.

For example, if an input to all is possibly undefined, the value after all won't be labeled as possibly undefined.

// pulumi.Input<string> | undefined
let input = possiblyUndefinedInput();
// pulumi.Output<string>
let original = pulumi.all([input])[0];
// pulumi.Output<string | undefined>
let newBehaviour = pulumi.all([input])[0];

function possiblyUndefinedInput(): pulumi.Input<string> | undefined {
  return undefined;
}

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

Using `all` currently looses type safety around the handling of input values which are possibly undefined.
By adding the explicit undefined option to each argument, the undefined case outside the inputty type does not get captured.

By removing the explicit `undefined` cases, the undefined is captured by the generic parameter and correctly carried through to the output type.

For example, if an input to `all` is possibly undefined, the value after `all` won't be labeled as possibly undefined.

```
// pulumi.Input<string> | undefined
let input = possiblyUndefinedInput();
// pulumi.Output<string>
let original = pulumi.all([input])[0];
// pulumi.Output<string | undefined>
let newBehaviour = pulumi.all([input])[0];

function possiblyUndefinedInput(): pulumi.Input<string> | undefined {
  return undefined;
}
```
@danielrbradley danielrbradley added area/sdks Pulumi language SDKs impact/usability Something that impacts users' ability to use the product easily and intuitively labels Oct 17, 2022
@pulumi-bot
Copy link
Contributor

Changelog

[uncommitted] (2022-10-17)

Bug Fixes

  • [sdk/nodejs] Fixes loss of undefined type case in all()
    #11048

Copy link
Member

@Frassle Frassle left a comment

Choose a reason for hiding this comment

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

Seems fine to me

@danielrbradley
Copy link
Member Author

bors merge

bors bot added a commit that referenced this pull request Oct 17, 2022
11048: Remove undefined cases from inputs to `all` function r=danielrbradley a=danielrbradley

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description
Using `all` currently looses type safety around the handling of input values which are possibly undefined. By adding the explicit undefined option to each argument, the undefined case outside the inputty type does not get captured.

By removing the explicit `undefined` cases, the undefined is captured by the generic parameter and correctly carried through to the output type.

For example, if an input to `all` is possibly undefined, the value after `all` won't be labeled as possibly undefined.

```typescript
// pulumi.Input<string> | undefined
let input = possiblyUndefinedInput();
// pulumi.Output<string>
let original = pulumi.all([input])[0];
// pulumi.Output<string | undefined>
let newBehaviour = pulumi.all([input])[0];

function possiblyUndefinedInput(): pulumi.Input<string> | undefined {
  return undefined;
}
```

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Daniel Bradley <daniel@pulumi.com>
@bors
Copy link
Contributor

bors bot commented Oct 17, 2022

Build failed:

@danielrbradley danielrbradley added this to the 0.79 milestone Oct 17, 2022
@danielrbradley
Copy link
Member Author

bors retry

bors bot added a commit that referenced this pull request Oct 17, 2022
11048: Remove undefined cases from inputs to `all` function r=danielrbradley a=danielrbradley

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description
Using `all` currently looses type safety around the handling of input values which are possibly undefined. By adding the explicit undefined option to each argument, the undefined case outside the inputty type does not get captured.

By removing the explicit `undefined` cases, the undefined is captured by the generic parameter and correctly carried through to the output type.

For example, if an input to `all` is possibly undefined, the value after `all` won't be labeled as possibly undefined.

```typescript
// pulumi.Input<string> | undefined
let input = possiblyUndefinedInput();
// pulumi.Output<string>
let original = pulumi.all([input])[0];
// pulumi.Output<string | undefined>
let newBehaviour = pulumi.all([input])[0];

function possiblyUndefinedInput(): pulumi.Input<string> | undefined {
  return undefined;
}
```

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Daniel Bradley <daniel@pulumi.com>
@bors
Copy link
Contributor

bors bot commented Oct 17, 2022

Build failed:

@danielrbradley
Copy link
Member Author

bors retry

@bors
Copy link
Contributor

bors bot commented Oct 18, 2022

Build succeeded:

@bors bors bot merged commit 0890cfc into master Oct 18, 2022
@bors bors bot deleted the danielrbradley/ts-all-types branch October 18, 2022 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sdks Pulumi language SDKs impact/usability Something that impacts users' ability to use the product easily and intuitively
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants