Skip to content

Conversation

@majiayu000
Copy link
Contributor

Summary

  • Add generic type parameter to PredictReturn<T> for type-safe data access
  • Add generic type parameter to PredictFunction for typed predictions
  • Add SubmitIterable interface methods (next, throw, return) for proper iterator typing

This allows users to call client.predict<MyType>() and get typed data:

type MyResponse = { text: string; confidence: number };
const result = await client.predict<MyResponse>("/predict", [input]);
// result.data is now typed as MyResponse instead of unknown
console.log(result.data.text); // TypeScript knows this is a string

Test plan

  • Added typing tests to verify generic functionality
  • All existing client tests pass
  • Build succeeds with proper type generation

Fixes #5462

Signed-off-by: majiayu000 [email protected]

- Add generic type parameter to PredictReturn<T> for type-safe data access
- Add generic type parameter to PredictFunction for typed predictions
- Add SubmitIterable interface methods (next, throw, return) for proper typing
- Add typing tests to verify generic functionality

This allows users to call client.predict<MyType>() and get typed data:
```typescript
type MyResponse = { text: string; confidence: number };
const result = await client.predict<MyResponse>("/predict", [input]);
// result.data is now typed as MyResponse
```

Fixes gradio-app#5462

Signed-off-by: majiayu000 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

better typing for @gradio/client

1 participant