PHPackages                             type-lang/types - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. type-lang/types

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

type-lang/types
===============

An AST nodes of the TypeLang

2.0.0-beta1(1mo ago)0997↓68.1%MITPHPPHP ^8.4CI passing

Since Jul 12Pushed 1mo agoCompare

[ Source](https://github.com/php-type-language/types)[ Packagist](https://packagist.org/packages/type-lang/types)[ RSS](/packages/type-lang-types/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

[ ![](https://github.com/php-type-language/.github/raw/master/assets/dark.png?raw=true)](https://github.com/php-type-language) [![PHP 8.1+](https://camo.githubusercontent.com/8b914b5bf0cea5533e30755fe3693c4feb92f38cd2fafab8e43526c90e83d5a2/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f74797065732f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/types) [![Latest Stable Version](https://camo.githubusercontent.com/9e890298c516a0bc63db0d4b5fd892e23df41d06cff729335adfb229cd085a19/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f74797065732f76657273696f6e3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/types) [![Latest Unstable Version](https://camo.githubusercontent.com/4b59aa381f71c5de4ff402981df9daac72e50029aa99877e3006c491c36d9511/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f74797065732f762f756e737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/types) [![License MIT](https://camo.githubusercontent.com/4e24f27775258ced851675723a4de08dcfc8716ca1f6c4d96f2e8d0bc42c8391/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f74797065732f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://raw.githubusercontent.com/php-type-language/types/blob/master/LICENSE)

 [![](https://github.com/php-type-language/types/workflows/tests/badge.svg)](https://github.com/php-type-language/types/actions)

---

The AST node classes (`TypeLang\Type\*`) for **TypeLang** — a declarative type language inspired by static analyzers like [PHPStan](https://phpstan.org/) and [Psalm](https://psalm.dev/docs/).

These plain, dependency-free DTOs are the shared vocabulary of the TypeLang ecosystem: the [parser](https://packagist.org/packages/type-lang/parser) produces them, the [printer](https://packagist.org/packages/type-lang/printer) renders them, and the [reader](https://packagist.org/packages/type-lang/reader) builds them from Reflection.

Full documentation is available at [typelang.dev](https://typelang.dev).

Installation
------------

[](#installation)

Install the package via [Composer](https://getcomposer.org):

```
composer require type-lang/types
```

**Requirements:**

- PHP 8.4+

Usage
-----

[](#usage)

Every node extends the abstract `Node` class and exposes an `$offset` (byte offset of the token in the original source). You usually get nodes from the parser, but they can also be constructed by hand.

### Identifiers and Names

[](#identifiers-and-names)

```
use TypeLang\Type\Identifier;
use TypeLang\Type\Name;

$id = Identifier::createFromString('non-empty-string');
$id->value;     // 'non-empty-string'
$id->isVirtual; // true  (contains "-", e.g. "array-key", "positive-int")
$id->isBuiltin; // false (e.g. "int", "bool", "null")
$id->isSpecial; // false (e.g. "self", "static", "parent")

$name = Name::createFromString('\TypeLang\Type\Node');
$name->isFullyQualified; // true
$name->first->value;     // 'TypeLang'
$name->last->value;      // 'Node'
```

### Building Type Nodes

[](#building-type-nodes)

```
use TypeLang\Type\Name;
use TypeLang\Type\NamedTypeNode;
use TypeLang\Type\NullableTypeNode;
use TypeLang\Type\UnionTypeNode;
use TypeLang\Type\TemplateArgumentListNode;
use TypeLang\Type\TemplateArgumentNode;

// int
new NamedTypeNode(Name::createFromString('int'));

// ?string
new NullableTypeNode(new NamedTypeNode(Name::createFromString('string')));

// int|string|null  (nested unions of the same kind are flattened)
new UnionTypeNode(
    new NamedTypeNode(Name::createFromString('int')),
    new NamedTypeNode(Name::createFromString('string')),
    new NamedTypeNode(Name::createFromString('null')),
);

// array
new NamedTypeNode(
    name: Name::createFromString('array'),
    arguments: new TemplateArgumentListNode([
        new TemplateArgumentNode(new NamedTypeNode(Name::createFromString('string'))),
        new TemplateArgumentNode(new NamedTypeNode(Name::createFromString('int'))),
    ]),
);
```

### Node Lists

[](#node-lists)

All list containers (shape fields, template arguments, callable parameters, ...) extend `NodeList` and implement `Countable`, `ArrayAccess` and `IteratorAggregate`:

```
count($list);   // number of items
$list[0];       // item by offset
$list->first;   // first item
$list->last;    // last item
foreach ($list as $item) { /* ... */ }
```

The package covers the full type grammar — unions and intersections, callables, conditional (ternary) expressions, class-constant masks, literals, shape fields and attributes. See the [documentation](https://typelang.dev) for the complete node reference.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance91

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

41d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Top Contributors

[![SerafimArts](https://avatars.githubusercontent.com/u/2461257?v=4)](https://github.com/SerafimArts "SerafimArts (9 commits)")

---

Tags

phplanguageasttypesnodestype-lang

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/type-lang-types/health.svg)

```
[![Health](https://phpackages.com/badges/type-lang-types/health.svg)](https://phpackages.com/packages/type-lang-types)
```

###  Alternatives

[ajthinking/archetype

Programmatically edit PHP and Laravel files.

2724.0M21](/packages/ajthinking-archetype)[rajentrivedi/tokenizer-x

TokenizerX calculates required tokens for given prompt

92261.6k3](/packages/rajentrivedi-tokenizer-x)[atanamo/php-codeshift

A PHP code transformation toolkit based on 'PHP-Parser'

32161.0k1](/packages/atanamo-php-codeshift)[type-lang/parser

Library for parsing and validating TypeLang syntax and converting it into AST nodes

5160.7k6](/packages/type-lang-parser)[butschster/proto-parser

Proto parser is a library for parsing Protocol Buffers files into AST

601.5k](/packages/butschster-proto-parser)

PHPackages © 2026

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