Last active
June 8, 2022 06:28
-
-
Save drupol/7d38df12be449984aadc23f2c5688937 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Snippet; | |
use loophp\TypedGenerators\TG; | |
use function PHPStan\Testing\assertType; | |
include __DIR__ . '/vendor/autoload.php'; | |
$sub1 = TG::array(TG::string(), TG::null()); | |
assertType('array<string, null>', $sub1()); // Passing | |
$sub2 = TG::array(TG::int(), TG::null()); | |
assertType('array<int, null>', $sub2()); // Passing | |
$sub3 = TG::array(TG::compound(TG::int(), TG::string()), TG::null()); | |
assertType('array<int|string, null>', $sub3()); // Passing | |
$sub4 = TG::iterator(TG::string(), TG::null())->add(TG::int(), TG::null()); | |
assertType('Iterator<int|string, null>', $sub4()); // Passing | |
$sub5 = TG::array(TG::string(), TG::null())->add(TG::int(), TG::null()); | |
assertType('array<int|string, null>', $sub5()); // Failing: Expected type array<int|string, null>, actual: array<string, null> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment