chargebee-typescript icon indicating copy to clipboard operation
chargebee-typescript copied to clipboard

Additional fields in hosted_page.checkout_new#subscription

Open L2jLiga opened this issue 5 years ago • 3 comments

In chargebee we used additional fields inside subscription like cf_filename which is impossible with this library and we have to cast subscription object as any

L2jLiga avatar Dec 07 '20 15:12 L2jLiga

Here my solution on how I solved this issue while preserving type safety and removing my linting errors.

First of all I extended the existing interface as follows:

interface customSubscriptionListParams extends _subscription.subscription_list_params {
  filename?: filter._string;
}

afterwards I just made a cast to this interface like:

this._chargebeeClient.subscription
        .list(<customSubscriptionListParams>{
          limit: 1,
          cf_filename: { is: filename },
        })

Hence, the type checks exists for the default variables but also for the additional custom field.

The only draw back I see is that this needs to be adapted per request instead of that there would be a central location which is exactly what @jaska120 asked for in https://github.com/chargebee/chargebee-typescript/issues/28.

Hence, Chargebee, if you have a solution to that, please let us know.

ced-mos avatar Apr 28 '23 08:04 ced-mos

Could do something like this too, alternative, has it's draw backs

declare module 'chargebee-typescript' {
  namespace _subscription {
    interface subscription_list_params {
      cf_filename?: filter._string;
    }
  }
}

dreadjr avatar Jul 17 '23 20:07 dreadjr

Hi @L2jLiga, I'm sorry for the dealyed response.

Thank you @ced-mos for the solution. I'd also suggest extending the predefined interface to include your custom field. @L2jLiga — were you able to try this and did it help?

cb-sriramthiagarajan avatar May 10 '24 09:05 cb-sriramthiagarajan