{"record":{"id":"79d9d00be6324451","repo":"pestphp/pest","slug":"the-given-closure-s-parameter-must-be-type-hinted","errorCode":null,"errorMessage":"The given closure's parameter must be type-hinted as the class string.","messagePattern":"The given closure's parameter must be type-hinted as the class string\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Mixins/Expectation.php","lineNumber":827,"sourceCode":"\n    /**\n     * @param  (Closure(Throwable): mixed)|string  $exception\n     * @return self<TValue>\n     */\n    public function toThrow(callable|string|Throwable $exception, ?string $exceptionMessage = null, string $message = ''): self\n    {\n        $callback = NullClosure::create();\n\n        if ($exception instanceof Closure) {\n            $callback = $exception;\n            $parameters = new ReflectionFunction($exception)->getParameters();\n\n            if (count($parameters) !== 1) {\n                throw new InvalidArgumentException('The given closure must have a single parameter type-hinted as the class string.');\n            }\n\n            if (! ($type = $parameters[0]->getType()) instanceof ReflectionNamedType) {\n                throw new InvalidArgumentException('The given closure\\'s parameter must be type-hinted as the class string.');\n            }\n\n            $exception = $type->getName();\n        }\n\n        try {\n            ($this->value)();\n        } catch (Throwable $e) {\n\n            if ($exception instanceof Throwable) {\n                // @phpstan-ignore-next-line\n                expect($e)\n                    ->toBeInstanceOf($exception::class, $message)\n                    ->and($e->getMessage())->toBe($exceptionMessage ?? $exception->getMessage(), $message);\n\n                return $this;\n            }\n","sourceCodeStart":809,"sourceCodeEnd":845,"githubUrl":"https://github.com/pestphp/pest/blob/1af74a215c3a89bc7a44fc6f9322e369eaad2423/src/Mixins/Expectation.php#L809-L845","documentation":"Error \"The given closure's parameter must be type-hinted as the class string.\" thrown in pestphp/pest.","triggerScenarios":"Thrown at src/Mixins/Expectation.php:827 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1af74a215c3a89bc7a44fc6f9322e369eaad2423","analyzedAt":"2026-08-21T02:16:38.132Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}