| name | typescript-api-types |
| description | Apply when defining API request/response types, DTOs, and shared types between frontend and backend. |
| version | 1.1.0 |
| tokens | ~650 |
| confidence | high |
| sources | ["https://www.typescriptlang.org/docs/handbook/utility-types.html","https://zod.dev/"] |
| last_validated | 2025-12-10T00:00:00.000Z |
| next_review | 2025-12-24T00:00:00.000Z |
| tags | ["typescript","api","types","validation"] |
When to Use
Apply when defining API request/response types, DTOs, and shared types between frontend and backend.
Patterns
Pattern 1: Request/Response Types
interface User {
id: string;
email: string;
name: string;
createdAt: Date;
updatedAt: Date;
}
type CreateUserDto = Omit<User, 'id' | 'createdAt' | 'updatedAt'>;
type UpdateUserDto = Partial<Omit<User, 'id'>> & Pick<User, 'id'>;
type UserResponse = Omit<User, 'createdAt' | 'updatedAt'> & {
createdAt: string;
updatedAt: string;
};
Pattern 2: API Response Wrapper
interface <T> {
: T;
?: {
?: ;
?: ;
?: ;
};
}
{
: {
: ;
: ;
?: <, []>;
};
}
<T> = <T> | ;
(): result is {
result;
}