Eden TanStack Query
API Reference

Types

All exported types from Eden TanStack Query

Types

This page documents all exported types from eden-tanstack-react-query.

Route Types

RouteDefinition

Base structure representing extracted type information from an Elysia route.

interface RouteDefinition {
  input: unknown   // Combined input type
  output: unknown  // Response type
  error: unknown   // Error type
}

HttpQueryMethod

HTTP methods used for query operations (read).

type HttpQueryMethod = 'get' | 'options' | 'head'

HttpMutationMethod

HTTP methods used for mutation operations (write).

type HttpMutationMethod = 'post' | 'put' | 'patch' | 'delete'

HttpMethod

All HTTP methods.

type HttpMethod = HttpQueryMethod | HttpMutationMethod

Error Types

EdenFetchError

Error type for Eden requests. It includes standard Error fields alongside the typed status code and response value. Eden derives message with String(value), so object response bodies may produce [object Object].

interface EdenFetchError<TStatus extends number = number, TValue = unknown> extends Error {
  status: TStatus
  value: TValue
}

Usage

import { useMutation } from '@tanstack/react-query'
import type { EdenFetchError } from 'eden-tanstack-react-query'

const { mutate, error } = useMutation(eden.users.post.mutationOptions())

// error is typed as EdenFetchError
if (error) {
  if (error.status === 400) {
    // Validation error
    console.log('Validation:', error.value)
  } else if (error.status === 500) {
    // Server error
    console.log('Server error:', error.value)
  }
}

Query Key Types

EdenQueryKey

Query key structure for TanStack Query cache.

type EdenQueryKey<TInput = unknown> =
  | [path: string[]]
  | [path: string[], meta: EdenQueryKeyMeta<TInput>]

// Examples:
[['users', 'get']]
[['users', 'get'], { input: { role: 'admin' } }]
[['posts', 'get'], {
  input: { limit: 10 },
  type: 'infinite',
  infinite: { initialPageParam: null }
}]

EdenMutationKey

Mutation key structure.

type EdenMutationKey = [path: string[]]

// Example:
[['users', 'post']]

EdenQueryKeyMeta

Metadata included in query keys.

type EdenQueryKeyMeta<TInput = unknown> = {
  input?: TInput
  type?: 'query' | 'infinite'
  infinite?: { initialPageParam?: unknown }
}

QueryType

Query type discriminator for cache organization.

type QueryType = 'query' | 'infinite' | 'any'

Type Inference Utilities

Route Type Inference

TypeDescription
InferRouteInput<TRoute, TMethod>Input type for route/method
InferRouteOutput<TRoute>Declared successful response types
InferRouteError<TRoute>Non-success response and transport error types

InferRouteInput

Extract input type from a RouteSchema.

// For GET/HEAD/OPTIONS: returns query parameters type
// For POST/PUT/PATCH/DELETE: returns body type
type InferRouteInput<TRoute, TMethod> = TMethod extends 'get' | 'head' | 'options'
  ? QueryParams
  : Body

InferRouteOutput

Extract the union of declared successful response types from a route. Treaty treats every status from 200 through 299 as successful and returns an empty string for bodyless 204 and 205 responses, regardless of their declared response schema.

InferRouteError

Extract the union of non-success response and transport error types from a route. The union also includes Treaty's EdenFetchError<503, unknown> transport failure because a custom fetcher can reject with any JavaScript value. Routes without a declared non-success response fall back to EdenFetchError<number, unknown>. A declared HTTP 503 response remains in the union, but narrowing only by status leaves value unknown because the same status can represent a transport failure.

InferRouteBody

Extract body type from a route.

InferRouteQuery

Extract query parameters type from a route.

InferRouteParams

Extract path parameters type from a route.

InferRouteHeaders

Extract headers type from a route.

ExtractRoutes

Extract routes schema from an Elysia app type.

type ExtractRoutes<TApp extends AnyElysia> = TApp['~Routes']

GetRoute

Get a specific route by path and method.

type UserRoute = GetRoute<typeof app, '/users/:id', 'get'>

ExtractPathParams

Extract path parameter names from a route path string.

type Params = ExtractPathParams<'/users/:id/posts/:postId'>
// => 'id' | 'postId'

PathParamsToObject

Create params object type from path string.

type Params = PathParamsToObject<'/users/:id/posts/:postId'>
// => { id: string; postId: string }

IsQueryMethod / IsMutationMethod

Type guards for method categorization.

Decorator Types

EdenOptionsProxy

Full decorated options proxy type for an Elysia app.

// Usage
type Proxy = EdenOptionsProxy<typeof app>
// Proxy.users.get.queryOptions(...)
// Proxy.users({ id: '1' }).get.queryOptions(...)
// Proxy.users.post.mutationOptions(...)

DecorateQueryProcedure

Decorator for query procedures (GET, OPTIONS, HEAD).

DecorateMutationProcedure

Decorator for mutation procedures (POST, PUT, PATCH, DELETE).

DecorateInfiniteQueryProcedure

Decorator for infinite query procedures.

DecorateRoute

Decorate a route based on HTTP method.

DecoratedRouteMethods

Decorate all methods of a route path.

DecorateRoutes

Recursively decorate all routes in an app's route tree.

Procedure Type Inference

TypeDescription
inferInput<TProcedure>Extract input type from decorated procedure
inferOutput<TProcedure>Extract output type from decorated procedure
inferError<TProcedure>Extract error type from decorated procedure

inferInput

Infer input type from a decorated procedure.

import type { inferInput } from 'eden-tanstack-react-query'

type UserInput = inferInput<typeof eden.users.get>

inferOutput

Infer output type from a decorated procedure.

import type { inferOutput } from 'eden-tanstack-react-query'

type UserOutput = inferOutput<typeof eden.users.get>

inferError

Infer error type from a decorated procedure.

import type { inferError } from 'eden-tanstack-react-query'

type UserError = inferError<typeof eden.users.get>

Options Types

EdenQueryOptions

Query options function type.

EdenMutationOptions

Mutation options function type.

EdenInfiniteQueryOptions

Infinite query options function type.

EdenQueryBaseOptions

Base options for Eden requests.

interface EdenQueryBaseOptions {
  eden?: {
    /** Abort request on component unmount */
    abortOnUnmount?: boolean
  }
}

EdenQueryOptionsResult

Result metadata added to query options.

interface EdenQueryOptionsResult {
  eden: {
    path: string
  }
}

Cursor Types

ExtractCursorType

Extract cursor type from input that has a cursor property.

type Cursor = ExtractCursorType<{ cursor?: string; limit: number }>
// => string

HasCursorInput

Check whether a non-union input has a usable required or optional top-level cursor key. any, never, union inputs, and required null-only cursors return false.

type HasCursor = HasCursorInput<{ cursor?: string }>  // true
type HasRequiredCursor = HasCursorInput<{ cursor: string }> // true
type NullOnlyCursor = HasCursorInput<{ cursor: null }> // false
type NoCursor = HasCursorInput<{ limit: number }>     // false

Utility Types

TypeDescription
DeepPartial<T>Makes all properties optional recursively
Simplify<T>Expands/simplifies complex types
IsAny<T>Check if type is any
IsNever<T>Check if type is never

DeepPartial

Make all properties optional deeply.

type Partial = DeepPartial<{ user: { name: string; email: string } }>
// => { user?: { name?: string; email?: string } }

Simplify

Simplify a type by expanding it (improves IDE display).

IsAny

Check if type is any.

IsNever

Check if type is never.

IsUnknown

Check if type is unknown.

See Also

On this page