Generic type inference failure

Bug report

If I write the mapping function like this I get error from phpstan that it is unable to infer the type
https://phpstan.org/r/81562057-9a62-46a3-8668-9a2bcc57398d

On the other hand if I make explicit cast to int I get error Casting to int something that's already int. so apparently phpstan is able to infer the type in this case
https://phpstan.org/r/49a2b60f-81e8-42ba-8655-82e0956abb98

Code snippet that reproduces the problem

https://phpstan.org/r/81562057-9a62-46a3-8668-9a2bcc57398d
https://phpstan.org/r/dc37f037-a491-49ae-a8b0-80d99114778b

Expected output

Either phpstan should infer the type or not showing error about useless cast

Did PHPStan help you today? Did it make you happy in any way?

No response