# ts-tagged

> Base generic type for weak nominal typing in Typescript

Latest version **1.0.0** (published 2018-02-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-tagged
pnpm add ts-tagged
yarn add ts-tagged
bun add ts-tagged
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-02-09 |
| First published | 2018-02-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 30.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | demurgos |
| Keywords | typescript, tagged, named, nominal |

## Links

- npm: https://www.npmjs.com/package/ts-tagged
- Repository: https://github.com/demurgos/ts-tagged
- Issues: https://github.com/demurgos/ts-tagged/issues
- npm.io page: https://npm.io/package/ts-tagged

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-02-09

## README

# ts-tagged

Defines the `Tagged<T, N>` generic type letting you created tagged types with base type `T` and name `N`.
Two variables of a tagged type can only be assigned to each other if they have the same base type and name.

This implements a weak form of nominal typing suitable for types shared across multiple packages.

## Installation

```bash
npm install -S ts-tagged
```

## Example

```typescript
import { Tagged } from "ts-tagged";

type Email = Tagged<string, "Email">;
type DisplayName = Tagged<string, "DisplayName">;

const email: Email = "foo@example.com";
const displayName: DisplayName = "Foo Bar";

function sendEmail(recipient: Email) {
  // ...
}

sendEmail(email); // OK
sendEmail(displayName); // Compilation error: the names don't match
sendEmail("bar@example.com"); // OK: Unnamed, but the base type matches
sendEmail(42); // Compilation error: The base type does not match
```

## License

[MIT License](./LICENSE.md)

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