# TypeScript types

The types the package exports, and what each one describes.

Each type is exported by name: `import type { PatrunRouter } from 'patrun'`.

| Type | What it is |
|---|---|
| `PatrunRouter<Data, Found>` | A router. `Data` is what a pattern holds, and `Found` what `find` answers, which is `Data` unless a customiser's function answers otherwise. Both are `any` if not given. |
| `PatrunOptions` | The options: `gex`, `interval`, and `order`. |
| `PatrunPattern` | A pattern: a map of keys to values. |
| `PatrunValue` | A value of a pattern: a string, a number, or a boolean. `null` and `undefined` are in the type too, as a key with either is left out. |
| `PatrunPatternOf<P>` | What an object of type `P` must be for `add`, `remove`, `get`, and `list` to take it: each of its members a `PatrunValue`. |
| `PatrunQuery` | What `find` is asked about: any map. |
| `PatrunSubject` | The earlier name of `PatrunQuery`, kept so that code that names it still compiles. Deprecated. |
| `PatrunEntry<Data, Found>` | One entry of what `list` gives: `pattern`, with its values as strings, `data`, and `find`, the customiser's function if there is one. |
| `PatrunCustomizer<Data, Found>` | A customiser: the function `add` calls with each pattern and its data. The data is `null` or `undefined` when `add` is given none. |
| `PatrunFind<Data, Found>`, `PatrunRemove<Data>` | The two functions a customiser may give for a pattern. |
| `PatrunMaker` | The type of `patrun` and of `Patrun`: called, or made with `new`, with the options or a customiser. |

`find` with `collect` given as `true` answers `Data[]`, as `collect` and `collectExact` do, and otherwise `Found | null`, as `findExact` does. `get` answers `Data | null`.

What compiles is not in every case what a function takes when it runs. A query may be any object to the types, so an array or an instance of a class compiles, and matches nothing. A string compiles neither as a query nor as a pattern, though `find` would answer `null` for it, and `list` `[]`. An instance of a class with no methods compiles as a pattern, and `add` throws a `TypeError` for it.
