This message was deleted.
# typescript
s
This message was deleted.
s
Here's the original TypeScript code I was using with Pulumi 1.x:
Copy code
const rawAzInfo = aws.getAvailabilityZones({
    state: "available",
});
let azNames: Array<string> = rawAzInfo.names;
let numberOfAZs: number = azNames.length;
Here's what I was trying to use w/ Pulumi 2.x:
Copy code
const rawAzInfo = pulumi.output(aws.getAvailabilityZones({
    state: "available",
}));
let azNames = rawAzInfo.apply(rawAzInfo => rawAzInfo.names);
let numberOfAZs = azNames.length;
TS complains that I can't define
azNames
as
Array<string>
because of type mismatch. If I remove the type definition, then I can't define
numberOfAZs
as a
number
due to type mismatch, and then that breaks some numerical operations later in the code.
As a relative newcomer to TypeScript, I'm a bit lost on how I can resolve this. Suggestions?
f
Since you’ll end up using the number later on, I would treat it as a promise (instead of wrapping in output). Then, either write your code w/in the
then
of the promise or use https://www.pulumi.com/docs/intro/languages/javascript/#entrypoint to use top-level
await
s
Thanks. Can you suggest some reading that might help me better understand working with promises? I've tried a couple variations of using
then
to no avail, so I think I need to spend some time understanding the concepts a bit better.
f
I don’t have a “go to” resource for that. I’ve heard good things about https://www.executeprogram.com/ — and their concurrency lesson seems to be among the free lessons you can try.
👍🏻 1