Sanity Library Reference Docs
    Preparing search index...

    Type Alias ClientParams<GroqString, Fallback>Experimental

    ClientParams: [GroqString] extends [{ __groqParams?: unknown }]
        ? NonNullable<(GroqString & { __groqParams?: unknown })["__groqParams"]>
        : Fallback

    The params type client.fetch(query, params) accepts for a query of type GroqString.

    A query carrying a __groqParams brand, such as the default export of a .groq file imported through @sanity-labs/groq-content-mapper, resolves to the branded params, so that the params passed alongside it are checked. Any other query resolves to Fallback, which defaults to QueryParams.

    Type Parameters

    Reading the brand is experimental and tracks the .groq file imports that @sanity-labs/groq-content-mapper is introducing. Like ClientReturn, this reads the brand structurally and never imports the package that produced the query.

    Unlike ClientReturn, this type sits in a parameter position, so it has to stay relatable while GroqString is still a type parameter: code that is generic over the query string, like function load<const Q extends string>(query: Q, params: QueryParams), must keep compiling. TypeScript never relates a value to a deferred conditional type that has an infer position, or that distributes over the type parameter it reads, which is why the brand is read through an indexed access and the check is written in the non-distributive tuple form. While deferred, TypeScript then checks the value against both branches, so the params are validated against Fallback exactly as they were before the brand existed.