chore(types): Keep intelisense while being more loosen (#10657)

**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.
This commit is contained in:
Adrien de Peretti
2024-12-18 18:12:31 +01:00
committed by GitHub
parent 9133957a94
commit 048620884b
3 changed files with 30 additions and 20 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/types": patch
---
chore(types): Keep intelisense while being more loosen

View File

@@ -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[]
>()
})

View File

@@ -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<
@@ -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.
*/