type-lang/printer

Library for rendering TypeLange AST nodes into it's string representation

Maintainers

Package info

github.com/php-type-language/printer

pkg:composer/type-lang/printer

Transparency log

Statistics

Installs: 37 978

Dependents: 5

Suggesters: 0

Stars: 1

Open Issues: 0

2.0.0-beta1 2026-07-12 18:26 UTC

This package is auto-updated.

Last update: 2026-07-12 18:43:23 UTC


README

PHP 8.4+ Latest Stable Version Latest Unstable Version License MIT

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>,
//     ...
// }