# @guanghechen/types

> Common type definitions for @guanghechen packages

Latest version **2.2.2** (published 2026-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @guanghechen/types
pnpm add @guanghechen/types
yarn add @guanghechen/types
bun add @guanghechen/types
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.2.2 |
| Published | 2026-09-12 |
| First published | 2023-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | guanghechen |
| Maintainers | lemonclown |

## Links

- npm: https://www.npmjs.com/package/@guanghechen/types
- Repository: https://github.com/guanghechen/sora/tree/@guanghechen/types@2.2.2
- Homepage: https://github.com/guanghechen/sora/tree/@guanghechen/types@2.2.2/packages/types#readme
- npm.io page: https://npm.io/package/@guanghechen/types

## Recent versions

- 2.2.2 (latest) — 2026-09-12
- 2.2.1 — 2026-07-10
- 2.2.0 — 2026-02-13
- 2.1.0 — 2026-02-13
- 2.0.1 — 2026-02-07
- 1.0.0 — 2024-09-20
- 1.0.0-alpha.11 — 2024-09-18
- 1.0.0-alpha.10 — 2024-02-03
- 1.0.0-alpha.9 — 2023-11-29
- 1.0.0-alpha.8 — 2023-11-18
- 1.0.0-alpha.6 — 2023-09-16
- 1.0.0-alpha.5 — 2023-09-14
- 1.0.0-alpha.4 — 2023-09-07
- 1.0.0-alpha.3 — 2023-09-06
- 1.0.0-alpha.2 — 2023-09-02
- … 1 more at https://npm.io/package/@guanghechen/types/versions

## README

<header>
  <h1 align="center">
    <a href="https://github.com/guanghechen/sora/tree/@guanghechen/types@2.2.2/packages/types#readme">@guanghechen/types</a>
  </h1>
  <div align="center">
    <a href="https://www.npmjs.com/package/@guanghechen/types">
      <img
        alt="Npm Version"
        src="https://img.shields.io/npm/v/@guanghechen/types.svg"
      />
    </a>
    <a href="https://www.npmjs.com/package/@guanghechen/types">
      <img
        alt="Npm Download"
        src="https://img.shields.io/npm/dm/@guanghechen/types.svg"
      />
    </a>
    <a href="https://www.npmjs.com/package/@guanghechen/types">
      <img
        alt="Npm License"
        src="https://img.shields.io/npm/l/@guanghechen/types.svg"
      />
    </a>
    <a href="#install">
      <img
        alt="Module Formats: cjs, esm"
        src="https://img.shields.io/badge/module_formats-cjs%2C%20esm-green.svg"
      />
    </a>
    <a href="https://github.com/nodejs/node">
      <img
        alt="Node.js Version"
        src="https://img.shields.io/node/v/@guanghechen/types"
      />
    </a>
    <a href="https://github.com/facebook/jest">
      <img
        alt="Tested with Jest"
        src="https://img.shields.io/badge/tested_with-jest-9c465e.svg"
      />
    </a>
    <a href="https://biomejs.dev/">
      <img
        alt="Code Style: Biome"
        src="https://img.shields.io/badge/code_style-biome-60a5fa.svg?style=flat-square"
      />
    </a>
  </div>
</header>
<br/>

Common type definitions for @guanghechen packages. Provides shared interfaces and types for
disposable resources, error handling, path resolution, and pub-sub patterns.

## Install

- npm

  ```bash
  npm install --save-dev @guanghechen/types
  ```

- yarn

  ```bash
  yarn add --dev @guanghechen/types
  ```

## Usage

### Disposable Types

```typescript
import type { IDisposable, IBatchDisposable } from '@guanghechen/types'

// IDisposable - Resource cleanup interface
class Connection implements IDisposable {
  disposed = false
  dispose(): void {
    this.disposed = true
    // cleanup logic
  }
}

// IBatchDisposable - Manage multiple disposables
class ResourceManager implements IBatchDisposable {
  disposed = false
  registerDisposable<T extends IDisposable>(disposable: T): void {
    // register for batch disposal
  }
  dispose(): void {
    // dispose all registered resources
  }
}
```

### Error Types

```typescript
import type { ISoraError, ISoraErrorCollector } from '@guanghechen/types'
import { ErrorLevelEnum } from '@guanghechen/types'

const error: ISoraError = {
  from: 'my-module',
  level: ErrorLevelEnum.ERROR,
  details: new Error('Something went wrong')
}

// ErrorLevelEnum: WARN = 4, ERROR = 5, FATAL = 6
```

### Path Types

```typescript
import type { IPathResolver, IWorkspacePathResolver } from '@guanghechen/types'

// IPathResolver methods:
// - basename, dirname, join, normalize, relative
// - isAbsolute, ensureAbsolute
// - isSafeRelative, ensureSafeRelative, safeRelative, safeResolve

// IWorkspacePathResolver - Workspace-scoped path operations:
// - root, pathResolver
// - isSafePath, ensureSafePath
// - relative, resolve
```

### Resource Types

```typescript
import type { IResource, ITextResource } from '@guanghechen/types'

// IResource<T> - Async resource operations
// - exists(): Promise<boolean>
// - load(): Promise<T | undefined>
// - save(data: T): Promise<void>
// - destroy(): Promise<void>

// ITextResource = IResource<string>
```

### Subscriber Types

```typescript
import type {
  ISubscriber,
  ISubscribable,
  ISubscribers,
  IUnsubscribable
} from '@guanghechen/types'

// ISubscriber<T> - Receives notifications, extends IDisposable
// ISubscribable<T> - Can be subscribed to
// IUnsubscribable - Can unsubscribe from notifications
// ISubscribers<T> - Manages multiple subscribers
```

### Utility Types

```typescript
import type { Diff, Mutable, PickPartial, PromiseOr } from '@guanghechen/types'

// Diff<T, U> - Remove properties in U from T
type OnlyInA = Diff<{ a: 1; b: 2 }, { b: 2 }> // { a: 1 }

// Mutable<T> - Remove readonly from all properties
type MutableUser = Mutable<{ readonly name: string }> // { name: string }

// PickPartial<T, K> - Make specific properties optional
type PartialName = PickPartial<{ name: string; age: number }, 'name'>
// { name?: string; age: number }

// PromiseOr<T> - Value or Promise of value
type MaybeAsync = PromiseOr<string> // string | Promise<string>
```

## Reference

- [homepage][homepage]

[homepage]:
  https://github.com/guanghechen/sora/tree/@guanghechen/types@2.2.2/packages/types#readme

---
_Source: https://npm.io/package/@guanghechen/types · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
