recursive.ts 415 B

12345678910111213141516
  1. // 递归类型 → $defs/$ref:直接自引用与通过成员间接自引用。
  2. interface TreeNode {
  3. value: number;
  4. children: TreeNode[];
  5. }
  6. interface Category {
  7. name: string;
  8. parent?: Category;
  9. items: string[];
  10. }
  11. const g = agent("g");
  12. const tree = await g.ask<TreeNode>("build a tree");
  13. const category = await g.ask<Category>("build a category");
  14. log(JSON.stringify(tree) + JSON.stringify(category));