Utility Types
Helper types for extracting context information
Utility Types
Helper types for extracting information from contexts and working with Bantai's type system.
ExtractContextShape
Extracts the shape type from a context.
type ExtractContextShape<TContext> = TContext extends ContextDefinition<
infer S,
Record<string, unknown>
>
? S
: neverUsage:
const context = defineContext(
z.object({
userId: z.string(),
age: z.number(),
})
);
type ContextShape = ExtractContextShape<typeof context>;
// ContextShape = { userId: z.ZodString; age: z.ZodNumber }ExtractContextTools
Extracts the tools type from a context.
type ExtractContextTools<TContext> = TContext extends ContextDefinition<
z.ZodRawShape,
infer TTools
>
? TTools
: Record<string, unknown>Usage:
const context = defineContext(
z.object({ userId: z.string() }),
{
tools: {
logger: console,
database: dbClient,
},
}
);
type ContextTools = ExtractContextTools<typeof context>;
// ContextTools = { logger: Console; database: DatabaseClient }Related Documentation
- Types - Core type definitions
- Function Signatures - Function type signatures