[英]Typescript compilation error - TS2769: No overload matches this call
I've update the typescript package to the latest version, and now I encounter this error during compilation:我已将 typescript package 更新到最新版本,现在在编译过程中遇到此错误:
TS2769: No overload matches this call
src/utils/search_module/index.ts:24:26 - error TS2769: No overload matches this call.
Overload 1 of 4, '(params?: Search<RequestBody<Record<string, any>>> | undefined, options?: TransportRequestOptions | undefined): TransportRequestPromise<...>', gave the following error.
Type 'unknown' is not assignable to type 'string | Buffer | Readable | Record<string, any> | undefined'.
Type 'unknown' is not assignable to type 'Record<string, any>'.
Overload 2 of 4, '(callback: callbackFn<Record<string, any>, Context>): TransportRequestCallback', gave the following error.
Argument of type '{ index: string; body: unknown; }' is not assignable to parameter of type 'callbackFn<Record<string, any>, Context>'.
Object literal may only specify known properties, and 'index' does not exist in type 'callbackFn<Record<string, any>, Context>'.
24 return await client.search({
~~~~~~~~~~~~~~~
25 index: ELASTIC_SEARCH_INDEX,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 body,
~~~~~~~~~~~~~~~~~~~~~
27 });
~~~~~~~~~~~~~~
this is the code:这是代码:
import { Client } from '@elastic/elasticsearch';
import nr from 'newrelic';
import config from 'config';
import constants from '../../../config/constants';
import { Hit } from './types';
export { search };
const ELASTIC_SEARCH_HOST = config.get<string>(constants.ELASTIC_SEARCH_ENDPOINT);
const ELASTIC_SEARCH_INDEX = config.get<string>(constants.ELASTIC_SEARCH_INDEX);
const client = new Client({
node: ELASTIC_SEARCH_HOST,
});
async function search<SourceResponse, HighlightResponse>(body: unknown): Promise<Hit<SourceResponse, HighlightResponse>> {
const result = await nr.startSegment('search_module:search', true, async () => {
return await client.search({
index: ELASTIC_SEARCH_INDEX,
body,
});
});
}
I looked in the definition of '@elastic/elasticsearch', yet could not find a way to resolve this error.我查看了“@elastic/elasticsearch”的定义,但找不到解决此错误的方法。
Please advise.请指教。
The type of body
parameter for your search
function is unknown
.您
search
的body
参数类型 function unknown
。 But the required type is requestParams.d.ts但所需的类型是requestParams.d.ts
export interface Search<T = RequestBody> extends Generic {
//...
body?: T;
}
So the body
property has RequestBody
type constraint.所以
body
属性有RequestBody
类型约束。
RequestBody
type: RequestBody
类型:
export type RequestBody<T = Record<string, any>> = T |
导出类型 RequestBody<T = Record<string, any>> = T | string |
字符串 | Buffer |
缓冲 | ReadableStream
可读流
body
can not be unknown
. body
不能unknown
。 It must be one of the Record<string, any>
, string
, Buffer
, and ReadableStream
types.它必须是
Record<string, any>
、 string
、 Buffer
和ReadableStream
类型之一。
That's why you got no overload signature matches your call
error.这就是为什么你
no overload signature matches your call
错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.