TypeScript with Solid Query
Solid Query is written in TypeScript and provides comprehensive type safety out of the box. This guide covers how to get the most out of TypeScript with Solid Query.Type Inference
Solid Query automatically infers types from your query and mutation functions:Generic Type Parameters
You can explicitly specify type parameters for more control:Type Parameters Explained
- TQueryFnData: The type returned by the queryFn
- TError: The type of errors that can be thrown (defaults to
Error) - TData: The type of data in the query result (useful with
select) - TQueryKey: The type of the query key (for type-safe query keys)
Query Options Type Safety
Use thequeryOptions helper for type-safe, reusable query configurations:
Mutation Type Safety
Mutations also support full type inference:Infinite Query Types
Type-safe infinite queries with proper page param typing:Custom Query Client Types
Extend the QueryClient with custom configuration types:Type-Safe Query Keys
Create a type-safe query key factory:Data Transformation with Select
Use theselect option to transform query data with full type safety:
Accessor Types
Solid Query uses SolidJS Accessors for reactive options:Type Utilities
Solid Query exports useful type utilities:Initial Data with Types
Error Handling Types
Best Practices
Follow these TypeScript best practices with Solid Query:
- Define Interfaces First: Always define your data interfaces before using them in queries
-
Use
queryOptions: Leverage thequeryOptionshelper for reusable, type-safe configurations - Explicit Return Types: Add explicit return types to your query and mutation functions
-
Use
as const: Useas constfor query keys to preserve literal types - Type Guards: Implement type guards for runtime type checking when needed
- Generic Helpers: Create generic helper functions for common query patterns
Version Support
Solid Query is tested against TypeScript versions:- TypeScript 5.0+
- TypeScript 5.1+
- TypeScript 5.2+
- TypeScript 5.3+
- TypeScript 5.4+
- TypeScript 5.5+
- TypeScript 5.6+
- TypeScript 5.7+ (latest)
Next Steps
Quick Start
Build your first type-safe Solid Query app
DevTools
Debug your queries with DevTools