From 072342e872833c916cc029e9d9f72b6468c500bf Mon Sep 17 00:00:00 2001 From: Daniel Bradley Date: Mon, 17 Oct 2022 14:24:58 +0100 Subject: [PATCH 1/2] Remove undefined cases from inputs to `all` function 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 | undefined let input = possiblyUndefinedInput(); // pulumi.Output let original = pulumi.all([input])[0]; // pulumi.Output let newBehaviour = pulumi.all([input])[0]; function possiblyUndefinedInput(): pulumi.Input | undefined { return undefined; } ``` --- sdk/nodejs/output.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/nodejs/output.ts b/sdk/nodejs/output.ts index 87908852b7a3..c73540fb5162 100644 --- a/sdk/nodejs/output.ts +++ b/sdk/nodejs/output.ts @@ -577,14 +577,14 @@ function createSimpleOutput(val: any) { */ /* eslint-disable max-len */ export function all(val: Record>): Output>>; -export function all(values: [Input | undefined, Input | undefined, Input | undefined, Input | undefined, Input | undefined, Input | undefined, Input | undefined, Input | undefined]): Output<[Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap]>; -export function all(values: [Input | undefined, Input | undefined, Input | undefined, Input | undefined, Input | undefined, Input | undefined, Input | undefined]): Output<[Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap]>; -export function all(values: [Input | undefined, Input | undefined, Input | undefined, Input | undefined, Input | undefined, Input | undefined]): Output<[Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap]>; -export function all(values: [Input | undefined, Input | undefined, Input | undefined, Input | undefined, Input | undefined]): Output<[Unwrap, Unwrap, Unwrap, Unwrap, Unwrap]>; -export function all(values: [Input | undefined, Input | undefined, Input | undefined, Input | undefined]): Output<[Unwrap, Unwrap, Unwrap, Unwrap]>; -export function all(values: [Input | undefined, Input | undefined, Input | undefined]): Output<[Unwrap, Unwrap, Unwrap]>; -export function all(values: [Input | undefined, Input | undefined]): Output<[Unwrap, Unwrap]>; -export function all(ds: (Input | undefined)[]): Output[]>; +export function all(values: [Input, Input, Input, Input, Input, Input, Input, Input]): Output<[Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap]>; +export function all(values: [Input, Input, Input, Input, Input, Input, Input]): Output<[Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap]>; +export function all(values: [Input, Input, Input, Input, Input, Input]): Output<[Unwrap, Unwrap, Unwrap, Unwrap, Unwrap, Unwrap]>; +export function all(values: [Input, Input, Input, Input, Input]): Output<[Unwrap, Unwrap, Unwrap, Unwrap, Unwrap]>; +export function all(values: [Input, Input, Input, Input]): Output<[Unwrap, Unwrap, Unwrap, Unwrap]>; +export function all(values: [Input, Input, Input]): Output<[Unwrap, Unwrap, Unwrap]>; +export function all(values: [Input, Input]): Output<[Unwrap, Unwrap]>; +export function all(ds: (Input)[]): Output[]>; export function all(val: Input[] | Record>): Output { // Our recursive `output` helper already does exactly what `all` needs to do in terms of the // implementation. Why have both `output` and `all` then? Currently, to the best of our From 3e3f1d6c645ccee367c720c794c0bae33a578c46 Mon Sep 17 00:00:00 2001 From: Daniel Bradley Date: Mon, 17 Oct 2022 14:29:47 +0100 Subject: [PATCH 2/2] Add to changelog --- changelog/pending/20221017--sdk-nodejs--fix-ts-all-types.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/pending/20221017--sdk-nodejs--fix-ts-all-types.yaml diff --git a/changelog/pending/20221017--sdk-nodejs--fix-ts-all-types.yaml b/changelog/pending/20221017--sdk-nodejs--fix-ts-all-types.yaml new file mode 100644 index 000000000000..b1ddaab2614e --- /dev/null +++ b/changelog/pending/20221017--sdk-nodejs--fix-ts-all-types.yaml @@ -0,0 +1,4 @@ +changes: +- type: fix + scope: sdk/nodejs + description: Fixes loss of undefined type case in `all()`