chargebee / chargebee-typescript

Typescript library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=typescript
MIT License
22 stars 16 forks source link

How to create type definitions for custom fields #28

Open jaska120 opened 2 years ago

jaska120 commented 2 years ago

Wodka's great work has been merged https://github.com/chargebee/chargebee-typescript/pull/23 and the productivity is much better now that we have typings in all the responses.

How would one proceed forward to add typings for custom fields? It is easy to override the return type per call level, but in ideal solution one would write type definitions eg. in types/chargebee.d.ts file and instruct tsconfig to look for the locally written types.

Could you please provide an example how eg. Customer & Subscription models' type definitions could be extended locally to augment custom field definitions to all the function calls in a single place?

declare module 'chargebee-typescript' {
  ... // What should be put here to augment type definitions for custom fields?
}
cb-sriramthiagarajan commented 4 months ago

Hi @jaska120, I'm sorry for the delayed response. One way to achieve this is to extend the predefined interface with a custom one. I’m sharing an example below for your reference.

import { _customer } from "chargebee-typescript";
import { filter } from "chargebee-typescript/lib/filter";

interface customCustomerListParams extends _customer.customer_list_params {
  string_0?: filter._string;
}

const response = await chargebeeInstance.customer
  .list(<customCustomerListParams>{ string_0: { is: "abc" } })
  .request();

Please let me know if this helps.