type-lang / printer
Library for rendering TypeLange AST nodes into it's string representation
2.0.0-beta1
2026-07-12 18:26 UTC
Requires
- php: ^8.4
- type-lang/types: ^2.0
Requires (Dev)
- phpstan/phpstan: ^2.2.5
- phpunit/phpunit: ^13.2.4
- type-lang/parser: ^2.0
This package is auto-updated.
Last update: 2026-07-12 18:43:23 UTC
README
About
The reference printer for TypeLang. It renders TypeLang\Type\* AST nodes
back into their string representation.
Two printers are provided:
NativeTypePrinter— outputs a valid, native PHP type declaration.PrettyTypePrinter— outputs the full PHPStan/Psalm-style type, formatted across multiple lines.
Full documentation is available at typelang.dev.
Installation
Install the package via Composer:
composer require type-lang/printer
Requirements:
- PHP 8.4+
Usage
Parse a type into an AST (using type-lang/parser),
then print it back with either printer:
$parser = new TypeLang\Parser\TypeParser(); $type = $parser->parse(<<<'PHP' array{ field1: (callable(Example, int): mixed), field2: list<Some>, ... } PHP); echo new TypeLang\Printer\NativeTypePrinter()->print($type); // array echo new TypeLang\Printer\PrettyTypePrinter()->print($type); // array{ // field1: callable(Example, int): mixed, // field2: list<Some>, // ... // }