class-extends-method.ts 619 B

123456789101112131415161718
  1. // A derived class with no constructor inherits the base constructor (implicit super
  2. // forwards the argument) and the base method; both dispatch through the shared derived
  3. // instance (extends weak-merges the base instance in). Expected: source -> ask#1,
  4. // ask#1 -> ask#2, ask#2 -> sink.
  5. const secret = await agent("writer").ask<string>("secret");
  6. class Base {
  7. data: string;
  8. constructor(s: string) {
  9. this.data = s;
  10. }
  11. reveal(): string {
  12. return this.data;
  13. }
  14. }
  15. class Derived extends Base {}
  16. const d = new Derived(secret);
  17. const out = await agent("reader").ask<string>(`use ${d.reveal()}`);
  18. return out;