Files
dpu-shared/README.md
2025-11-17 21:22:16 +01:00

142 lines
2.6 KiB
Markdown

# Shared TypeScript Types
This package contains shared TypeScript type definitions used across multiple applications.
## Setup
### 1. Initialize the package
```bash
npm install
npm run build
```
### 2. Push to Git
```bash
git init
git add .
git commit -m "Initial commit: shared types package"
git remote add origin <your-git-repo-url>
git push -u origin main
```
## Usage in Other Projects
### Option 1: Install from Git (HTTPS)
Add to your project's `package.json`:
```json
{
"dependencies": {
"@your-org/shared-types": "git+https://github.com/your-org/shared-types.git"
}
}
```
Or install via command:
```bash
npm install git+https://github.com/your-org/shared-types.git
```
### Option 2: Install from Git (SSH)
```json
{
"dependencies": {
"@your-org/shared-types": "git+ssh://git@github.com:your-org/shared-types.git"
}
}
```
### Option 3: Install specific branch or tag
```json
{
"dependencies": {
"@your-org/shared-types": "git+https://github.com/your-org/shared-types.git#v1.0.0"
}
}
```
Or for a branch:
```json
{
"dependencies": {
"@your-org/shared-types": "git+https://github.com/your-org/shared-types.git#develop"
}
}
```
## Using the Types
```typescript
import { User, ApiResponse, Status } from '@your-org/shared-types';
const user: User = {
id: '123',
email: 'user@example.com',
name: 'John Doe',
createdAt: new Date(),
updatedAt: new Date()
};
const response: ApiResponse<User> = {
success: true,
data: user,
message: 'User retrieved successfully'
};
const status = Status.Active;
```
## Updating the Package
When you make changes to the types:
1. Update the version in `package.json`
2. Build the package: `npm run build`
3. Commit and push changes
4. Update consuming applications: `npm update @your-org/shared-types`
## Development Workflow
### Adding New Types
1. Create new `.ts` files in the `src/` directory
2. Export types from `src/index.ts`
3. Build and test: `npm run build`
4. Commit changes and push
### Versioning
Follow semantic versioning:
- **MAJOR**: Breaking changes
- **MINOR**: New features, backward compatible
- **PATCH**: Bug fixes, backward compatible
### Best Practices
- Keep types focused and modular
- Use clear, descriptive names
- Document complex types with JSDoc comments
- Avoid coupling to specific implementations
- Export everything through `index.ts`
## Structure
```
shared-types/
├── src/
│ ├── index.ts # Main export file
│ └── types.ts # Type definitions
├── dist/ # Compiled output (generated)
├── package.json
├── tsconfig.json
├── .gitignore
└── README.md
```