let 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);