setter-field.ts 487 B

12345678910111213
  1. // Object-literal set accessor: assigning `box.val = secret` must record the assigned
  2. // value as the setter's param, whose body captures it into `captured`, which a
  3. // downstream ask reads. Setters are handled crudely (by property name, globally).
  4. let captured = "";
  5. const box = {
  6. set val(v: string) {
  7. captured = v;
  8. },
  9. };
  10. const secret = await agent("writer").ask<string>("secret");
  11. box.val = secret;
  12. const out = await agent("reader").ask<string>(`use ${captured}`);
  13. return out;