Sanity Library Reference Docs
    Preparing search index...

    Type Alias ResolveDocument<TDocumentType, TSchemaId>Beta

    ResolveDocument: TSchemaId extends keyof SanitySchemasByResource
        ? DocumentIn<TSchemaId, TDocumentType>
        : UsesLegacyLookup<TSchemaId, SanitySchemasByResource, TDocumentType> extends true
            ? SanityDocument<TDocumentType, TSchemaId>
            :
                | DocumentIn<
                    MatchingKeys<SanitySchemasByResource, TSchemaId>,
                    TDocumentType,
                >
                | SanityDocument<TDocumentType, TSchemaId>

    Resolves a document type for one resource.

    A resource registered in SanitySchemasByResource is answered from there and only there: a document type absent from a registered resource is never, never the legacy union, because an unrelated union looks precise while describing the wrong dataset.

    A key known only as a pattern, such as ${string}.${string} from a DocumentHandle<'post'> prop or a resource chosen at runtime, resolves to the union of the document type across the registered resources it can match: the document is one of those. A key that matches no registration, or a lookup whose document type is also only string, uses the experimental Typegen declarations as before, which is what keeps saved generated files working.

    Type Parameters

    • TDocumentType extends string = string
    • TSchemaId extends string = string