Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create type definitions for custom fields #28

Open
jaska120 opened this issue Jan 28, 2022 · 1 comment
Open

How to create type definitions for custom fields #28

jaska120 opened this issue Jan 28, 2022 · 1 comment

Comments

@jaska120
Copy link

Wodka's great work has been merged #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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants