Improve type info on param hooks (#4438)

# Description of Changes
Changes it so that callers of `useBaseTool` know what actual type the
parameters hook that they passed in returned, so they can actually make
use of any extra methods that that params hook has.
This commit is contained in:
James Brunton 2025-09-15 14:28:18 +01:00 committed by GitHub
parent cfdb6eaa1e
commit 7dad484aa7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,12 +6,12 @@ import { ToolOperationHook } from './useToolOperation';
import { BaseParametersHook } from './useBaseParameters';
import { StirlingFile } from '../../../types/fileContext';
interface BaseToolReturn<TParams> {
interface BaseToolReturn<TParams, TParamsHook extends BaseParametersHook<TParams>> {
// File management
selectedFiles: StirlingFile[];
// Tool-specific hooks
params: BaseParametersHook<TParams>;
params: TParamsHook;
operation: ToolOperationHook<TParams>;
// Endpoint validation
@ -33,13 +33,13 @@ interface BaseToolReturn<TParams> {
/**
* Base tool hook for tool components. Manages standard behaviour for tools.
*/
export function useBaseTool<TParams>(
export function useBaseTool<TParams, TParamsHook extends BaseParametersHook<TParams>>(
toolName: string,
useParams: () => BaseParametersHook<TParams>,
useParams: () => TParamsHook,
useOperation: () => ToolOperationHook<TParams>,
props: BaseToolProps,
options?: { minFiles?: number }
): BaseToolReturn<TParams> {
): BaseToolReturn<TParams, TParamsHook> {
const minFiles = options?.minFiles ?? 1;
const { onPreviewFile, onComplete, onError } = props;