# ast-types-flow

> Flow types for the Javascript AST

Latest version **0.0.8** (published 2023-04-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install ast-types-flow
pnpm add ast-types-flow
yarn add ast-types-flow
bun add ast-types-flow
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2023-04-15 |
| First published | 2015-09-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 123 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | kyldvs |
| Maintainers | kyldvs |
| Keywords | flow, ast, javascript |

## Links

- npm: https://www.npmjs.com/package/ast-types-flow
- Repository: https://github.com/kyldvs/ast-types-flow
- Homepage: https://github.com/kyldvs/ast-types-flow#readme
- Issues: https://github.com/kyldvs/ast-types-flow/issues
- npm.io page: https://npm.io/package/ast-types-flow

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 0.0.8 (latest) — 2023-04-15
- 0.0.7 — 2015-10-30
- 0.0.6 — 2015-10-28
- 0.0.5 — 2015-10-28
- 0.0.4 — 2015-09-30
- 0.0.3 — 2015-09-14
- 0.0.2 — 2015-09-14
- 0.0.1 — 2015-09-14

## README

# ast-types-flow

Flow types for the Javascript AST. Based off of [benjamn/ast-types](https://github.com/benjamn/ast-types).

## Usage

First install `ast-types-flow` via npm, then you can import any of the types
that are exported.

```javascript
/* @flow */

import type {Node} from 'ast-types-flow';

function getName(node: Node): string {
  switch (node.type) {
    case 'Identifier':
      return node.name;

    case 'ClassDeclaration':
      return node.id.name; // Error, id could be null.

    case 'FunctionDeclaration':
      return node.id.name; // Fine if it's always there.

    case 'FunctionExpression':
      if (node.id) {
        return node.id.name; // Can refine id to make sure it exists.
      } else {
        return 'Unknown';
      }

    case 'Literal':
      return node.name; // Error, Literals don't have names, don't be silly.
  }
  return 'Unknown';
}
```

## How it works

A notion of "extends" is added to the Flow syntax via comments. A transform is
included that will compile the source code into useful disjoint union types
based on how the different types extend each other. For example:

```javascript
type Node = {
  common: string,
};

type Foo = {
  // extends Node
  foo: string,
};

type Bar = {
  // extends Node
  bar: number,
};
```

Will be transformed into:

```javascript
type Node = {
  type: 'Foo',
  _Foo: void,
  common: string,
  foo: string,
} | {
  type: 'Bar',
  _Bar: void,
  common: string,
  bar: number,
};

type Foo = {
  type: 'Foo',
  _Foo: void,
  common: string,
  foo: string,
};

type Bar = {
  type: 'Bar',
  _Foo: void,
  common: string,
  bar: number,
};
```

A few things to note:

1. The type `Node` would more ideally be compiled into `Foo | Bar` but then the
disjoint union cannot be properly refined. For now we have to duplicate the
complete definitions.
2. Each entry in a disjoint union has to be structurally unique or Flow will
have an error on the definition. That is why the private `_Foo: void` fields
appear in the types.

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