
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.
Install the package via Composer:
composer require type-lang/printerRequirements:
- PHP 8.4+
Parse a type into an AST (using type-lang/parser),
then print it back with either printer:
$parser = newTypeLang\Parser\TypeParser();
$type = $parser->parse(<<<'PHP' array{ field1: (callable(Example, int): mixed), field2: list<Some>, ... }
PHP);
echonewTypeLang\Printer\NativeTypePrinter()->print($type);
// arrayechonewTypeLang\Printer\PrettyTypePrinter()->print($type);
// array{// field1: callable(Example, int): mixed,// field2: list<Some>,// ...// }