iteration-fanout-element-mutation.ts 628 B

123456789101112131415
  1. // Element mutation through the iteration binding. At runtime the forEach callback
  2. // parameter and the for...of loop variable ARE the array elements (references), so a
  3. // field write through them mutates the arrays; the later read of a[0].note / b[0].note
  4. // carries ask#1's artifact into ask#2.
  5. // Expected: source -> ask#1; ask#1 -> ask#2 (MUST); ask#2 -> sink.
  6. const secret = await agent("writer").ask<string>("secret");
  7. const a = [{ note: "" }];
  8. const b = [{ note: "" }];
  9. a.forEach((x) => {
  10. x.note = secret;
  11. });
  12. for (const y of b) {
  13. y.note = secret;
  14. }
  15. return agent("reader").ask<string>(`${a[0]!.note} ${b[0]!.note}`);