Open weirdan opened 1 year ago
I found these snippets:
Could be extended to functions and callable, and include return types:
/**
* @param function-args<$func> $args
* @return function-return<$func>
*/
function call_user_func(callable $func, ...$args) { ... }
Rationale
Some methods may have signatures based on other methods. One particular example is Laravel's
Dispatchable
trait, where methods have signatures based on constructor signature.It would be great if we had a way to specify something like this:
https://psalm.dev/r/bd50e7e47e
Prior art
Parameters<T>
,ConstructorParameters<T>
andReturnType<T>
in Typescript.Typescript, however, builds those types on function signature types + generics +
infer
: https://github.com/microsoft/TypeScript/blob/a3092c798ad9f165b0f7cba964a2c7b976cd30d0/lib/lib.es5.d.ts#L1601