@kellanjs/actioncraft
Version:
Fluent, type-safe builder for Next.js server actions.
21 lines (20 loc) • 1.06 kB
TypeScript
import type { CraftedAction, InferCraftedActionResult } from "./actions.js";
import type { PossibleErrors } from "./errors.js";
import type { InferRawInput } from "./schemas.js";
/**
* Extracts the raw input type from a crafted action.
*/
export type InferInput<T> = T extends CraftedAction<infer _TConfig, infer TSchemas, any, // eslint-disable-line @typescript-eslint/no-explicit-any
any> ? InferRawInput<TSchemas> : never;
/**
* Extracts the complete result type from a crafted action.
*/
export type InferResult<T> = T extends CraftedAction<infer TConfig, infer TSchemas, infer TErrors, infer TData> ? InferCraftedActionResult<TConfig, TSchemas, TErrors, TData> : never;
/**
* Extracts the success data type from a crafted action.
*/
export type InferData<T> = T extends CraftedAction<any, any, any, infer TData> ? TData : never;
/**
* Extracts possible error types from a crafted action.
*/
export type InferErrors<T> = T extends CraftedAction<infer TConfig, infer TSchemas, infer TErrors, any> ? PossibleErrors<TErrors, TConfig, TSchemas> : never;