Init
This commit is contained in:
27
shared/README.md
Normal file
27
shared/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Shared Types
|
||||
|
||||
This directory contains shared types and schemas that are used by both the frontend and backend.
|
||||
|
||||
## Usage
|
||||
|
||||
### Frontend
|
||||
```typescript
|
||||
import { ApiResponse } from '../shared/types'
|
||||
```
|
||||
|
||||
### Backend
|
||||
Consider using `ts-rs` to generate TypeScript types from Rust structs:
|
||||
|
||||
```rust
|
||||
use ts_rs::TS;
|
||||
|
||||
#[derive(Serialize, TS)]
|
||||
#[ts(export)]
|
||||
pub struct ApiResponse<T> {
|
||||
pub success: bool,
|
||||
pub data: Option<T>,
|
||||
pub message: Option<String>,
|
||||
}
|
||||
```
|
||||
|
||||
This will generate TypeScript definitions that stay in sync with your Rust types.
|
||||
14
shared/types.ts
Normal file
14
shared/types.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
// Shared types between frontend and backend
|
||||
export interface ApiResponse<T> {
|
||||
success: boolean
|
||||
data?: T
|
||||
message?: string
|
||||
}
|
||||
|
||||
export interface HelloResponse {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface HelloQuery {
|
||||
name?: string
|
||||
}
|
||||
Reference in New Issue
Block a user