<?php declare(strict_types=1); /** * @template T */ class Example { /** @param T $inner */ public function __construct(public mixed $inner) { } /** * @return T */ public function get(): mixed { return $this->inner; } /** * @template U * @param callable(T): U $callback * @return U */ public function map(callable $callback): mixed { return $callback($this->inner); } /** * @template U * @param callable(T): U $callback * @return Example<U> */ public function chainMap(callable $callback): Example { return new self($callback($this->inner)); } } $example = new Example(123); // phpstorm understands this as int|mixed $value = $example->get(); // phpstorm understands this as int|mixed $value = $example->map(fn (int $val): string => (string) $val); function requiresInt(int $input) { } // phpstorm still sees this more crazy one as int|mixed.. $value = $example->chainMap(fn ($val) => (string) $val) ->chainMap(fn ($val) => new Example($val)) ->chainMap(fn ($val) => new Example($val)) ->chainMap(fn ($val) => $val->get()->get()) ->get(); // but psalm understands // psalm: InvalidScalarArgument: Argument 1 of requiresInt expects int, "123" provided requiresInt($value);
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`