Skip to main content

TypeScript Server Actions Return Type

File Structure

Return Type Folder 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 and message fields are required and must not be null
  • data and error 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.