Shopify / shopify-api-js

Shopify Admin API Library for Node. Accelerate development with support for authentication, graphql proxy, webhooks
MIT License
944 stars 394 forks source link

Provide more complete typings by decoupling object field descriptions and functionality #374

Closed tkalliom closed 1 year ago

tkalliom commented 2 years ago

Overview/summary

Decouple data structure typings from current REST resource classes into types or interfaces. Then the typings can be made a lot more useful with nested objects having proper typings, instead of being just Record<string, unknown>.

Motivation

What inspired this enhancement?

Currently, if you do something like for (const lineItem of order.line_items), lineItem is just { [key: string]: unknown }. This means missing out on the benefits of typings. It would be desirable for nested objects to be typed as well. (Contrast with https://github.com/MONEI/Shopify-api-node which has richer types like this.)

Here's an excerpt of what Order currently looks like:

export class Order extends Base {
  public static API_VERSION = ApiVersion.April22;
  // other static members

  public static async find(...): Promise<Order | null> {
    ...
  }
  // other methods

  public line_items: {[key: string]: unknown}[] | null;
  public app_id: number | null;
  public billing_address: {[key: string]: unknown} | null;
  // other fields
}

I'm thinking of something along the lines of:

interface IOrder {
  public line_items: {
    fulfillable_quantity: number;
    // other fields
  }[] | null;

  public app_id: number | null;

  public billing_address: ICustomerAddress | null;

  // other fields
}

export class Order extends Base, IOrder {
  // static members and methods
}
github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days.

github-actions[bot] commented 1 year ago

We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!