sparse-intern-71089
08/03/2023, 4:19 PMclever-sunset-76585
08/03/2023, 4:35 PMlet numTasks = vpc.publicSubnets.apply(subnets => subnets.length);
// that will work when we only have 1 subnet in the Test-vpc but for now
if (nom === 'test'){
numTasks = 1;
}
When you don't define an explicit type for numTasks
, the compiler sees that its type is the result of the apply()
which is Output<T>
but then later when you try to re-assign that to a number
, it's an error.
let numTasks: number = vpc.publicSubnets.apply(subnets => subnets.length);
Here you are explicitly defining the type to be a number
which is not correct because you are defining one type but then assigning a value of a different type, Output<T>
.
TypeScript supports union types, which allows you to do:
let numTasks: number | Output<number> = vpc.publicSubnets.apply(subnets => subnets.length);
BUT you have another option. Pulumi has a built-in type called Input<T>
which is a union of similar to the above. It's what all resource's properties are and it's why you can either give them plain values or promise-like values.
let numTasks: Input<number> = vpc.publicSubnets.apply(subnets => subnets.length);
full-eve-52536
08/03/2023, 4:35 PMnumTasks
can either be of type `Output<any>`(Which is a Pulumi-specific type), or it can be of type number
. I think what you want is:
let numTasks: number | Output<number>
polite-napkin-90098
08/03/2023, 5:29 PMlittle-cartoon-10569
08/03/2023, 8:41 PMpulumi.Input<number>
.little-cartoon-10569
08/03/2023, 8:41 PMpulumi.Output<number>
and change the if-clause to
if (nom === 'test'){
numTasks = pulumi.output(1);
}
little-cartoon-10569
08/03/2023, 8:42 PMfull-eve-52536
08/03/2023, 8:42 PMpulumi.Output()
as a function? Hmm..didn't know that. TILlittle-cartoon-10569
08/03/2023, 8:43 PMpulumi.Output
is a type. pulumi.output()
is a function.little-cartoon-10569
08/03/2023, 8:43 PMpulumi.Output
.