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

[FEATURE] Separate type for customFields #1467

Open
krzysztofkaszanek opened this issue Nov 20, 2024 · 0 comments
Open

[FEATURE] Separate type for customFields #1467

krzysztofkaszanek opened this issue Nov 20, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@krzysztofkaszanek
Copy link

Description

api-gen package generates the following type for all customFields:

customFields?: GenericRecord;

where

type GenericRecord =
  | never
  | null
  | string
  | string[]
  | number
  | {
      [key: string]: GenericRecord;
    };

This caused issues for us as soon as we enabled typechecking in the project:
product.customFields['custom_product_short_description']
Image

It seems that GenericRecord type is too generic for customFields. customFields will never be a string or number directly.

What we plan to use for now as a workaround is the following type:

type GenericRecordValue =
    | never
    | null
    | string
    | string[]
    | number
    | {
          [key: string]: GenericRecord
      }
type GenericRecord = {
    [key: string]: GenericRecordValue
}

It's far from ideal as we need to edit the auto-generated storeApiTypes.d.ts manually.

I think the best solution would be to introduce new, more specific type for customFields field.

Use Case

Introducing new type specifically for customFields will resolve the type errors when trying to access custom field value.

Proposed Solution

Introduce separate, more specific type for customFields

Alternatives Considered

No response

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Developer Backlog
Development

No branches or pull requests

1 participant