TypeScript Server Actions Return Type
File Structure
TypeScript Return Type Definition
export type ServerActionResponse<T = any> = {
data?: T;
error?: string;
status: number;
message: string;
};
The ServerActionResponse
type is designed to provide a consistent return structure for all server actions. In this type definition:
status
andmessage
fields are required and must not be nulldata
anderror
fields are optional, but should not be null when provided- The type is generic, allowing you to specify the data type that will be returned
This standardized response format helps maintain consistency across all server actions and makes client-side handling more predictable.