2025-11-17 21:22:16 +01:00
2025-11-17 21:22:16 +01:00
2025-11-17 21:22:16 +01:00
2025-11-17 21:22:16 +01:00
2025-11-17 21:22:16 +01:00
2025-11-17 21:22:16 +01:00
2025-11-17 21:22:16 +01:00

Shared TypeScript Types

This package contains shared TypeScript type definitions used across multiple applications.

Setup

1. Initialize the package

npm install
npm run build

2. Push to Git

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:

{
  "dependencies": {
    "@your-org/shared-types": "git+https://github.com/your-org/shared-types.git"
  }
}

Or install via command:

npm install git+https://github.com/your-org/shared-types.git

Option 2: Install from Git (SSH)

{
  "dependencies": {
    "@your-org/shared-types": "git+ssh://git@github.com:your-org/shared-types.git"
  }
}

Option 3: Install specific branch or tag

{
  "dependencies": {
    "@your-org/shared-types": "git+https://github.com/your-org/shared-types.git#v1.0.0"
  }
}

Or for a branch:

{
  "dependencies": {
    "@your-org/shared-types": "git+https://github.com/your-org/shared-types.git#develop"
  }
}

Using the Types

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
Description
Types for DPU
Readme 638 KiB
Languages
TypeScript 100%