type-lang / printer
Library for rendering TypeLange AST nodes into it's string representation
2.0.0-beta2
2026-09-12 21:45 UTC
Requires
- php: ^8.1
- type-lang/types: ^2.0
Requires (Dev)
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^10.5|^11.0|^12.0|^13.0
- type-lang/parser: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-12 22:53:02 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.1+
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>, // ... // }