Skip to content

Commit 5c6de1e

Browse files
committed
[sc-11365] generic type for ApiFetchCallback's parameter
1 parent 975fa8b commit 5c6de1e

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/apifetch.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ interface RecommendOptions {
1010
configurationKey?: string;
1111
}
1212

13-
/* eslint-disable @typescript-eslint/no-explicit-any */
14-
export interface ApiFetchCallback {
15-
(response: any): void;
13+
interface Suggestion {
14+
value: string;
15+
}
16+
17+
export interface SuggestionsResponse {
18+
suggestions: Suggestion[];
19+
}
20+
21+
export interface ApiFetchCallback<T = any> {
22+
(response: T): void;
1623
}
17-
/* eslint-enable @typescript-eslint/no-explicit-any */
1824

1925
interface SourceDocuments {
2026
page: number;

src/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import executeApiFetch, { ApiFetchCallback, ExecuteApiFetch } from './apifetch';
1+
import executeApiFetch, {
2+
ApiFetchCallback,
3+
ExecuteApiFetch,
4+
SuggestionsResponse
5+
} from './apifetch';
26
import {
37
getDocument,
48
saveDocument,
@@ -146,7 +150,7 @@ class Client {
146150
return putSentimentClick(this.apiHostname, this.sitekey, conversationId, sentimentValue);
147151
}
148152

149-
suggestions(prefix: string, callback: ApiFetchCallback): void {
153+
suggestions(prefix: string, callback: ApiFetchCallback<SuggestionsResponse>): void {
150154
if (!prefix || !callback || !util.isFunction(callback)) {
151155
throw new Error('Illegal suggestions parameters. Should be (prefix, callbackFunction)');
152156
}

0 commit comments

Comments
 (0)