This message was deleted.
# typescript
s
This message was deleted.
l
The pulumi app is in most ways a normal TypeScript module. Exports from the module (index.ts) are its exports. All other files are their own modules, which the Pulumi app can use. But the exports of those other files are their exports, not index.ts' exports. The first few paragraphs on this page explains it well: https://www.typescriptlang.org/docs/handbook/modules.html
Exports have rules from TypeScript, including that they must be at the top level, not inside classes or functions.
s
I ran into this as well and now just pass anything to export back to index.ts for actual export
👍 1
l
You can export things from one module without importing them / passing them back. The syntax is under "Re-exports" on the link above.
a
@little-cartoon-10569 I understand exports. I didn't think that aggregating exports is called re-exports, but I do that as well. But pulumi (maybe typescript) has a feature where you can dynamically add properties (with values), in a function, to the
exports
object and they get exported when you are in the main pulumi index.ts. I couldn't get that approach to work in the modules, which are basically only an exported function. So now, my module functions all return a
{}:any
and they are all collected and then added to the
exports
object in the top-level index.ts.
Copy code
var toOutputs : any = {};

var newOutputs = module.Function();
toOutputs = {...toOutputs, ...newOutputs}
<repeat as needed>

Object.keys(toOutputs).forEach( key => { exports[key] = toOutputs[key]});
l
Ah yes. Sorry, haven't used that notation. It seems to be normal CommonJS/TS though? I see it on that same page I linked earlier, under "Code Generation for Modules" / CommonJS. The Stacks page in the Pulumi docs uses that notation and says that only top level exports become stack outputs: https://www.pulumi.com/docs/intro/concepts/stack/#outputs
a
I wonder if I could pass the
exports
object into my module functions. 😄