I don't think you can do this by casting or wrapping: the type of a
pulumi.output(x as Promise<X>)
is going to be an
Output<Promise<X>
.
Rather, everywhere that you might use an Output or Promise actually takes an Input, which is a union type including both the Output and the Promise. So you can just ignore the requirement for an Output, and use the Promise directly.
little-cartoon-10569
04/03/2021, 6:11 AM
So you could rewrite your example code as
Copy code
const output = new Promise<Map<string, string>>((resolve, reject) => new Map<string, string>());
And use that output variable anywhere that needs an Input.
g
gifted-island-55702
04/06/2021, 7:24 AM
Thank you @little-cartoon-10569. The issue is I want to expose that value as an output property of my ComponentResource class. My understanding is that I should use pulumi.Output type in such cases.
l
little-cartoon-10569
04/06/2021, 8:44 PM
You can use any type. Things that you can pass an Output<x> to (almost) always take an Input<x>, which is a union type defined as
x | Promise<x> | Output<x>
. You can export strings, Promises of lists, Outputs of numbers.. whatever you like.
little-cartoon-10569
04/06/2021, 8:47 PM
And "outputs" of ComponentResources are just properties, there is no magic to them. The only "output" variables are those exported from Pulumi projects / stacks.
Any public properties of ComponentResources, of any time, can be exported and Pulumi will handle it. (With the gotcha that there is no marshalling / unmarshalling, so if you're exporting non-primitives, you're going to have to marshal / unmarshall them yourself).
No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.