Skip to content

Commit

Permalink
chore(types): Keep intelisense while being more loosen (medusajs#10657)
Browse files Browse the repository at this point in the history
**What**
Keep the autocompletion for the fields API in Query APIs while being more flexible in order to prevent limitation from our depth limit but also to be more flexible when assigning string[] coming from the API for example.
  • Loading branch information
adrien2p authored Dec 18, 2024
1 parent 9133957 commit 0486208
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-ways-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/types": patch
---

chore(types): Keep intelisense while being more loosen
29 changes: 15 additions & 14 deletions packages/core/types/src/modules-sdk/__tests__/remote-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ describe("RemoteQuery", () => {
it("should return the correct type for fields when using a string entry point", () => {
type Result = RemoteQueryObjectConfig<"simple_product">["fields"]
expectTypeOf<Result>().toEqualTypeOf<
(
| "*"
| "id"
| "handle"
| "title"
| "variants.id"
| "variants.*"
| "sales_channels.id"
| "sales_channels.*"
| "sales_channels.name"
| "sales_channels_link.*"
| "sales_channels_link.product_id"
| "sales_channels_link.sales_channel_id"
)[]
| (
| "*"
| "id"
| "handle"
| "title"
| "variants.id"
| "variants.*"
| "sales_channels.id"
| "sales_channels.*"
| "sales_channels.name"
| "sales_channels_link.*"
| "sales_channels_link.product_id"
| "sales_channels_link.sales_channel_id"
)[]
| string[]
>()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export type RemoteQueryObjectConfig<TEntry extends string> = {
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
> extends never
? string[]
: ObjectToRemoteQueryFields<
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
>[]
:
| ObjectToRemoteQueryFields<
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
>[]
| string[]
}

export type RemoteQueryObjectFromStringResult<
Expand All @@ -36,9 +38,11 @@ export type RemoteQueryInput<TEntry extends string> = {
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
> extends never
? string[]
: ObjectToRemoteQueryFields<
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
>[]
:
| ObjectToRemoteQueryFields<
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
>[]
| string[]
/**
* Pagination configurations for the returned list of items.
*/
Expand Down

0 comments on commit 0486208

Please sign in to comment.