Review a generated payment declaration

from Declaration files
TypeScript 6 advanced 6 min 4 issues to find

Review this generated local declaration and consumer wrapper.

Type a named-export JavaScript package whose findCharge can return undefined, and expose a public receipt without the internal 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;
}

generated code is illustrative, not from any one model

Open in playground
Report an error