PHPackages                             hershel-theodore-layton/type-visitor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hershel-theodore-layton/type-visitor

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hershel-theodore-layton/type-visitor
====================================

A visitor core for reified types

v1.2.1(8mo ago)07.8k↓53.8%2MITHackCI passing

Since Aug 23Pushed 1w ago1 watchersCompare

[ Source](https://github.com/hershel-theodore-layton/type-visitor)[ Packagist](https://packagist.org/packages/hershel-theodore-layton/type-visitor)[ RSS](/packages/hershel-theodore-layton-type-visitor/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (4)Versions (11)Used By (2)

type-visitor
============

[](#type-visitor)

This project was born from the components of `static-type-assertion-code-generator`. The [BigSwitch](./src/_Private/visit.hack) used to be tied to `new SomeTypeStructure()`. You are now able to slot in whatever functionality you need.

`HTL\TypeVisitor` allows you to visit a reifiable type by implementing the [Visitor&lt;Tt, Tf&gt;`](./src//Visitor.hack) interface. For an example use, see [TypenameVisitor](./src/TypenameVisitor.hack).

Call [TypeVisitor\\visit()](./src/visit.hack) to get going.

The [TAlias](./src/TAlias.hack) type contains three fields for advanced use:

- `"alias"`
    - The name `"ExampleName"` on the LHS of this statement:

    ```
    type ExampleName = int;
    ```
- `"opaque"`:
    - True iff the alias is declared using `newtype` instead of plain `type`.
- `"counter"`:
    - A unique integer for each call to your visitor functions.
    - This sequence starts at `1` and increases with each call to `$visitor->x()`.

**Warning for users on hhvm 4.102 through 4.108.**

At some point between hhvm version 4.102 and 4.108, hhvm changed the kind of `enum class` from `enum` to `class`. This means that `->enum()` will be called instead of `->class()`. If your visitors need to have consistent behavior on all supported hhvm versions, you must add a reflection based check at the top of `function enum(...)` and call `->class()` if the argument is a `classname` of an `enum class`.

Go ahead and build something awesome:

- Generate documentation based on Hack types.
- Create a "weak" assertion / coercion library.
- Use it to generate mock data of a particular type.

Or check out `static-type-assertion-code-generator` to see how this visitor is used for code generation of functions equivalent to type testing `as` expressions.

### The stability of this API

[](#the-stability-of-this-api)

The following warning is part of the [type-assert](https://github.com/hhvm/type-assert)README:

> `TypeStructure`, `type_structure()`, and `ReflectionTypeAlias::getTypeStructures()`are experimental features of HHVM, and not supported by Facebook or the HHVM team... We strongly recommend moving to TypeAssert\\matches() and TypeCoerce\\match() instead.

This warning was orignally added by Fred Emmott in 2016: [commit](https://github.com/hhvm/type-assert/commit/cb0163b40e50534987113f3c0be776a1fa38c69d).

This project uses `TypeStructure`, in the same way that `TypeAssert\matches()` does. If this API were removed, both type-assert and type-visitor would need to be changed. *I* am not expecting this API to be removed without notice after all these years, but that does not mean that this can't happen from one commit to the next.

**What this means for you:** This API may be broken in future versions of HHVM. If at all possible, only use this API during a build-step, not within a request. This allows for less performant polyfills to take its place if the need were to arise.

### Note to future copyright lawyers

[](#note-to-future-copyright-lawyers)

The work on which this visitor is based was created in 2021. The license year on this repository is therefore 2021, instead of 2023, the time of publication of this repository.

I am not under the impression that these ~1000 lines will be useful for their intended purpose at the end of the copyright term.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance82

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~89 days

Recently: every ~40 days

Total

10

Last Release

243d ago

Major Versions

v0.2.0 → v1.0.02024-11-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/d16d159b7061287c506d4ab44d05ae042bc4ec697116d1bd132a007634d9ff21?d=identicon)[Hershel Theodore Layton](/maintainers/Hershel%20Theodore%20Layton)

---

Top Contributors

[![hershel-theodore-layton](https://avatars.githubusercontent.com/u/81193606?v=4)](https://github.com/hershel-theodore-layton "hershel-theodore-layton (44 commits)")

### Embed Badge

![Health badge](/badges/hershel-theodore-layton-type-visitor/health.svg)

```
[![Health](https://phpackages.com/badges/hershel-theodore-layton-type-visitor/health.svg)](https://phpackages.com/packages/hershel-theodore-layton-type-visitor)
```

###  Alternatives

[hhvm/hsl

The Hack Standard Library

1171.2M55](/packages/hhvm-hsl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
