审查生成的支付声明

来自 声明文件
TypeScript 6 高级 6分钟 找出 4处问题

审查这份生成的本地声明与使用方包装函数。

为一个使用命名导出的 JavaScript 包补充类型;findCharge 可能返回 undefined,并且公开收据不得包含内部 access token。

TypeScript
declare module "legacy-payments" {
  interface Charge {
    id: string;
    cents: number;
    accessToken: string;
  }

  function findCharge(id: string): Charge;
  const client: { findCharge: typeof findCharge };
  export default client;
}

import client from "legacy-payments";

type PublicReceipt = { id: string; cents: number };

export function publicReceipt(id: string) {
  const charge = client.findCharge(id);
  return charge;
}

生成代码仅作示例,不代表任何特定模型

在试验场中打开
报告错误