# typesafe-decorators

> Better types for experimental/legacy TypeScript decorators

Latest version **2.0.2** (published 2023-05-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install typesafe-decorators
pnpm add typesafe-decorators
yarn add typesafe-decorators
bun add typesafe-decorators
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2023-05-06 |
| First published | 2023-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tamás Hegedűs |
| Maintainers | sorgloomer |
| Keywords | typescript, typesafe, decorator, ioc, inference |

## Links

- npm: https://www.npmjs.com/package/typesafe-decorators
- Homepage: https://github.com/sorgloomer/ts-typesafe-decorators
- Funding: https://github.com/sponsors/sorgloomer
- npm.io page: https://npm.io/package/typesafe-decorators

## 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

- 2.0.2 (latest) — 2023-05-06
- 2.0.1 — 2023-05-06
- 2.0.0 — 2023-05-06
- 1.1.0 — 2023-04-24
- 1.0.3 — 2023-04-21
- 1.0.2 — 2023-04-21
- 1.0.1 — 2023-04-21
- 1.0.0 — 2023-04-21

## README

# typesafe-decorators

<p>
  <a href="https://github.com/sorgloomer/ts-typesafe-decorators/actions?query=branch%3Amaster"><img src="https://github.com/sorgloomer/ts-typesafe-decorators/actions/workflows/test.yml/badge.svg?event=push&branch=master" alt="Test" /></a>
  <a href="https://opensource.org/licenses/MIT" rel="nofollow"><img src="https://img.shields.io/github/license/sorgloomer/ts-typesafe-decorators" alt="License"></a>
</p>

<div>
  <a href="https://github.com/sorgloomer/ts-typesafe-decorators/tree/master/packages/typesafe-decorators">GitHub</a>
  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
  <a href="https://www.npmjs.com/package/typesafe-decorators">npm</a>
  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
  <a href="https://github.com/sorgloomer/ts-typesafe-decorators/issues">Issues</a>
  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
  <a href="https://twitter.com/hege_hegedus">@hege_hegedus</a>
  <br />
</div>

# Intro

Typescript 5 made it possible for legacy experimental decorators to check the types of the parameters they are applied
to.

This repository contains helper libraries to enforce the correct types of injected services at compile time, for your
favorite ioc container.


### Example

```typescript
import { TypedPropertyDecorator, TypedParameterDecorator } from 'typesafe-decorators';

declare const StringLogger: TypedPropertyDecorator<string, 'get'>;
declare const EnumValidator: TypedPropertyDecorator<'foo' | 'bar' | 'baz', 'set'>
 & TypedParameterDecorator<'foo' | 'bar' | 'baz', 'set'>;

class Foo {
  @StringLogger // OK
  private x1!: 'a' | 'b';

  @StringLogger
  // ^^^^^^^^^^  Type of property is not assignable to type of decorator
  private x2!: number;

  @EnumValidator   // OK
  private x3!: string;

  @EnumValidator
  // ^^^^^^^^^^^  Type of decorator is not assignable to type of property
  private x4!: 'foo' | 'bar';

  private foo(
    @EnumValidator
    p1: string,
    @EnumValidator
    // ^^^^^^^^^^^  Type of decorator is not assignable to type of parameter
    p2: 'foo' | 'bar',
  ) {}
}
```


### See also

 * [Typesafe Decorators for Inversify](https://github.com/sorgloomer/ts-typesafe-decorators/tree/master/packages/inversify-typesafe-decorators)
 * [Typesafe Decorators for NestJS](https://github.com/sorgloomer/ts-typesafe-decorators/tree/master/packages/nestjs-typesafe-decorators)

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