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 | HttpMutationMethodError 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
pathParams?: EdenQueryKeyPathParam[]
type?: 'query' | 'infinite'
infinite?: { initialPageParam?: unknown }
}EdenQueryKeyPathParam
An ordered path-parameter application, exported by eden-tanstack-react-query. pathIndex is the zero-based index of the path segment where the parameters were applied. It is -1 for parameters applied directly to the root proxy. entries records the parameter names and values separately from request input.
interface EdenQueryKeyPathParam {
pathIndex: number
entries: [name: string, value: unknown][]
}QueryType
Query type discriminator for cache organization.
type QueryType = 'query' | 'infinite' | 'any'Type Inference Utilities
Route Type Inference
| Type | Description |
|---|---|
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
: BodyInferRouteOutput
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.
Response types follow Treaty's response conversions, with the serialization
limits described below. Elysia form() responses expose their payload object,
and ReadableStream<T> is typed as AsyncGenerator<T, void, unknown>.
Sync and async generators that yield no values
and return an object resolve to that object type. Generators that can both yield
and return a value include the async generator and return value in their union.
The streamed branch completes with void; its server-side return value is not
delivered. An early void return decodes to an empty string, so generators that
can yield and return void include "" in their output union.
When updating existing code, read form payload fields directly and consume streams
with for await...of. A generator response may need narrowing
before iteration.
Multipart and stream decoding limits
These types inherit limitations from native Treaty. Multipart fields and stream chunks can decode to values that differ from their inferred types.
For multipart responses, form() preserves the original payload field types in
inference, but non-file fields are serialized as strings. For example,
form({ age: 42, active: true }) decodes to
{ age: '42', active: 'true' }, although the fields are still typed as number
and boolean. Prefer string and File
fields in multipart responses, and explicitly parse and validate fields that need
other types.
For streams, the inferred yield type retains the original chunk type, but Treaty
can decode bytes to text and parse text as JSON. A ReadableStream<Uint8Array>
containing encoded hello can yield a string, and a ReadableStream<string>
containing 42 can yield the number 42. Decoding depends on content type,
parser configuration, and wire boundaries. When the decoded shape is uncertain,
pass each value to a validator that accepts unknown before using methods such
as subarray() or relying on a particular object shape.
InferRouteOutputAll
Extract the response record for every declared status, with the same response
conversions and decoding limits described above. This utility preserves status
keys and declared 204/205 values;
InferRouteOutput applies the bodyless-status override.
InferRouteError
Extract the union of non-success response and transport error types from a route.
Declared error value types use the same form, stream, and generator conversions
and decoding limits as successful responses.
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
| Type | Description |
|---|---|
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 }>
// => stringHasCursorInput
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 }> // falseUtility Types
| Type | Description |
|---|---|
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
- Query Keys - Query key utilities
- queryOptions - Query options factory
- mutationOptions - Mutation options factory