# ts-type-visitor

Latest version **0.2.2** (published 2020-11-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-type-visitor
pnpm add ts-type-visitor
yarn add ts-type-visitor
bun add ts-type-visitor
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2020-11-21 |
| First published | 2019-08-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 73 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Saito Nakamura |
| Maintainers | saitonakamura |
| Keywords | typescript, typescript-transformer, typescript-compiler-api |

## Links

- npm: https://www.npmjs.com/package/ts-type-visitor
- Repository: https://github.com/ts-type-makeup/ts-type-visitor
- Homepage: https://github.com/ts-type-makeup/ts-type-visitor#readme
- Issues: https://github.com/ts-type-makeup/ts-type-visitor/issues
- npm.io page: https://npm.io/package/ts-type-visitor

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

- 0.2.2 (latest) — 2020-11-21
- 0.2.1 — 2020-11-21
- 0.2.0 — 2020-11-21
- 0.1.3 — 2019-08-15
- 0.1.2 — 2019-08-11
- 0.1.1 — 2019-08-11
- 0.1.0 — 2019-08-11

## README

# Typescript type visitor

<p>
  <a href="https://www.npmjs.com/package/ts-type-visitor">
    <img alt="Npm" src="https://img.shields.io/npm/v/ts-type-visitor.svg?style=flat-square" />
  </a>
  <a href="https://travis-ci.org/ts-type-makeup/ts-type-visitor.svg?branch=master">
    <img alt="Travis CI build status" src="https://travis-ci.org/ts-type-makeup/ts-type-visitor.svg?branch=master" />
  </a>
</p>

It's a function that takes a `ts.TypeChecker` and a `ts.Type` and traverses the type building easy-to-use `TypeModel`

```ts
const typeVisitor = (checker: TypeChecker, type: Type): TypeModel => {...}

export type TypeModel =
  | TypeModelString
  | TypeModelNumber
  | TypeModelUnion
  | ...

export interface TypeModelString {
  readonly kind: "string";
}

export interface TypeModelNumber {
  readonly kind: "number";
}

export interface TypeModelUnion {
  readonly kind: "union";
  readonly types: TypeModel[];
}

...
```

It's different from Typescript compiler API built-in model by the next properties

1. It has a `kind` field (`string`, `number`, `object`) which is string literal union so it allows you to do [exhaustive checks](https://basarat.gitbooks.io/typescript/docs/types/discriminated-unions.html)
2. It simplifies the API itself, there's no methods, flags and this kind of stuff, only `kind` and additional data
3. It has a built-in special types, `array` and `tuple` namely, that is kinda tricky to detect using vanilla compiler API

Basically you want to use it along with a compiler API, just using it for the `ts.Type`, and using Typescript compiler API for everything else, e.g. emitting new code, analyzing AST etc.

## Installation

```bash
npm i -D ts-type-visitor
# or
yarn add --dev ts-type-visitor
```

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