Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

Repository files navigation

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

About

[READ ONLY] 🖌️ Library for rendering TypeLange AST nodes into it's string representation

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Releases

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.