@emuready/shared
v0.7.35
Published
Shared tRPC types for apps using the EmuReady API
Readme
@emuready/shared
Type-only package providing tRPC helper types for use in React Native and other external applications.
Installation
npm install @emuready/sharedUsage
This package exports tRPC inference helper types that you can use with your main project's AppRouter type.
Step 1: Import the AppRouter type
In your React Native app, import the AppRouter type from your main project:
// In your React Native app
import type { AppRouter } from '../path/to/main/project/src/shared-types'
import type { inferRouterInputs, inferRouterOutputs } from '@emuready/shared'Step 2: Create type-safe helpers
// Create type-safe router output types
export type RouterOutput = inferRouterOutputs<AppRouter>
// Create type-safe router input types
export type RouterInput = inferRouterInputs<AppRouter>Step 3: Use in your components
// Get the output type of a specific tRPC endpoint
type ListingsOutput = RouterOutput['listings']['getAll']
// Get the input type of a specific tRPC endpoint
type CreateListingInput = RouterInput['listings']['create']
// Use in your components
const MyComponent = () => {
const listings = trpc.listings.getAll.useQuery() // Fully typed!
// listings.data is typed as ListingsOutput
return (
<View>
{listings.data?.map(listing => (
<Text key={listing.id}>{listing.title}</Text>
))}
</View>
)
}Available Exports
inferRouterInputs<T>- Extract input types from a tRPC routerinferRouterOutputs<T>- Extract output types from a tRPC router
Type Safety
This approach provides full type safety for your tRPC API calls in React Native while keeping the shared package lightweight and dependency-free.