This message was deleted.
s
This message was deleted.
e
b
no, as I want it to be accessible in this way `buckets.sourceBucket.name``
e
Then what you've got is correct
b
But I'm not using the
bucket
object 😕 , what about if I want to create the buckets using
aws.s3.bucket()
in the for each loop?
in addition, what is called in typescript that
buckets
type? map? dict?
e
Ah you need to give TypeScript a few more type hints for that:
Copy code
type Bucket = {
    name: string;
    bucket?: aws.s3.Bucket;
  };

let buckets : {[key: string]: Bucket } = {
    sourceBucket: { name: "emr-source" },
    outputBucket: { name: "emr-output" },
    emrLogsBucket: { name: "emr-logs" },
    emrStudioBucket: { name: "emr-studio" },
};

for (const k in buckets) {
    buckets[k].bucket = ...
}
b
What about if I want to initialize the source bucket later?
e
That's why it's marked
?
b
Copy code
let buckets: { [key: string]: aws.s3.Bucket } = {
  source:,
  output:,
  emrLogs:,
  emrStudio:,
};
and If I want to do it in this way?
how can I define the objects (source, output, emrLogs, etc..) without initializing them?
e
I think:
Copy code
let buckets: { [key: string]: aws.s3.Bucket? } = {
  source: undefined,
  output: undefined,
  emrLogs: undefined,
  emrStudio: undefined,
};
b
nops
Type 'undefined' is not assignable to type 'Bucket'.ts(2322)
e
aws.s3.Bucket?
<- I think
?
works in that location if not then you want
aws.s3.Bucket | undefined
b
yeah that | undefined did the trick
Copy code
let buckets: { [key: string]: aws.s3.Bucket | undefined } = {
  emrSource: undefined,
  emrOutput: undefined,
  emrLogs: undefined,
  emrStudio: undefined,
};

Object.entries(buckets).forEach(([key, value]) => {
  value = new aws.s3.Bucket(key, { forceDestroy: true });
});
this works, thanks
🙌 1
do you think that is OK this code?
or is there any better way of doing that? (creating a list of buckets)
e
I think you need to fix the
value =
That will assign the variable value, while you probably want
buckets[key] =
But otherwise yeh that seems reasonable
b
done
thanks!