class-instance.ts 312 B

123456789101112131415
  1. // 类实例(自定义 class)承载行为,不是纯数据 —— 拒绝。
  2. class Widget {
  3. constructor(public id: string) {}
  4. render(): string {
  5. return this.id;
  6. }
  7. }
  8. interface Holder {
  9. widget: Widget;
  10. }
  11. const g = agent("g");
  12. const v = await g.ask<Holder>("go"); // error
  13. log(JSON.stringify(v));