PHPackages                             type-lang/printer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. type-lang/printer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

type-lang/printer
=================

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

1.4.0(9mo ago)138.1k↑93.6%5MITPHPPHP ^8.1CI passing

Since Mar 1Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/php-type-language/printer)[ Packagist](https://packagist.org/packages/type-lang/printer)[ RSS](/packages/type-lang-printer/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (5)Versions (12)Used By (5)

[ ![](https://github.com/php-type-language/.github/raw/master/assets/dark.png?raw=true)](https://github.com/php-type-language) [![PHP 8.4+](https://camo.githubusercontent.com/c5c50365f509c0071dc87b6faed68b2c1466fa5edac984a71c65c5264cc23b66/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7072696e7465722f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/printer) [![Latest Stable Version](https://camo.githubusercontent.com/ceb8a4f1fbef641183409744aba845c3d1c95c8592eb2a76624ed5d67c007b03/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7072696e7465722f76657273696f6e3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/printer) [![Latest Unstable Version](https://camo.githubusercontent.com/0fce33a4247857db60451bb79c56c4dd74a5201128a006b3e3e528b3004caa08/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7072696e7465722f762f756e737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/printer) [![License MIT](https://camo.githubusercontent.com/b7491b754a028baba9f924911949a22fc6c11fc0f20d1abea24fba21ea217bc9/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7072696e7465722f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://raw.githubusercontent.com/php-type-language/printer/blob/master/LICENSE)

 [![](https://github.com/php-type-language/printer/workflows/tests/badge.svg)](https://github.com/php-type-language/printer/actions)

---

About
-----

[](#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](https://typelang.dev).

Installation
------------

[](#installation)

Install the package via [Composer](https://getcomposer.org):

```
composer require type-lang/printer
```

**Requirements:**

- PHP 8.4+

Usage
-----

[](#usage)

Parse a type into an AST (using [`type-lang/parser`](https://packagist.org/packages/type-lang/parser)), then print it back with either printer:

```
$parser = new TypeLang\Parser\TypeParser();

$type = $parser->parse(
