Check out the code below:
let m1 = new Map<string, PolicyDocument>([
[
"key1",
new PolicyDocument({
statements: [
new PolicyStatement({
actions: ["sqs:PublishMessage"],
effect: Effect.ALLOW,
resources: ["aa:bb:cc"]
})
]
})
]
]);
let m2 = new Map<string, PolicyDocument>([
[
"key2",
new PolicyDocument({
statements: [
new PolicyStatement({
actions: ["sqs:GetMessage"],
effect: Effect.ALLOW,
resources: ["aa:bb:cc"]
})
]
})
]
]);
let m3 = new Map<string, PolicyDocument>([
[
"key3",
new PolicyDocument({
statements: [
new PolicyStatement({
actions: ["sqs:DeleteMessage"],
effect: Effect.ALLOW,
resources: ["aa:bb:cc"]
})
]
})
]
]);
const result: Map<string, PolicyDocument> = {
...m1,
...m2,
...m3
};
console.log(result);
Could anyone explain why result
is not populated with the three key-value pairs as expected? It seems like I am missing a fundamental TypeScript concept.
I made sure to use the built-in Map type and avoided importing anything external.
Edit
Appreciate the guidance on how to properly merge Maps. My concern lies in
- why there are no compile-time errors in the provided code?
- why the merging technique doesn't produce the desired output?