https://pulumi.com logo
Title
l

little-cartoon-10569

10/17/2022, 4:57 AM
I'm attempting to impose an API on the stack exports of one project, for use in dependent projects. For example, if my parent project exports properties from a Person resource, with properties age and name, I want my project to export a
interface Person { age: number; name: string}
that other projects can use when dereferencing a stack reference. My assumption is that it's not worth trying to use the Person interface in the exporting project. I shouldn't try to put this in my parent project's index.ts:
export steve: Person = { age: steve.age, name: steve.name };
Instead, I should be happy with this:
export steve = { age: steve.age, name: steve.name };
I assume that the type wrangling I'd have to go through to make the one interface usable in both places is likely to be complicated, and to hide intent. In the parent project, the interface would contain a pile of `pulumi.Output`s (from all the resources providing the values I want to export)). In the dependent projects, all the values are known at the same time so the only Output I need in code is the one wrapping the Person object(
const steve: pulumi.Output<Person> =  stackref.requireOutput("steve") as pulumi.Output<Person>
). Is there an easy / clear way to use the one interface in both places? Am I correct in not even trying?
v

victorious-church-57397

10/17/2022, 6:21 AM
One way you could get this done relatively simply and quickly is to publish your config types as a package and install as a dependency in your projects? Or publish your parent stack as a package as well and pull the types in from there?
l

little-cartoon-10569

10/17/2022, 8:04 AM
Yes that's what we're doing. The problem is using the type in two places: the two uses of the type are sufficiently different that it's not worth using the same type in both cases.
I have no trouble publishing an NPM package with the correct type for use in dependent projects. The problem is using that type in the same project as I'm publishing it from: it's just not similar enough.