You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/typescript.asciidoc
+21-60Lines changed: 21 additions & 60 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
1
[[typescript]]
2
+
2
3
== TypeScript support
3
4
4
5
The client offers a first-class support for TypeScript, since it ships the type
@@ -7,76 +8,36 @@ definitions for every exposed API.
7
8
NOTE: If you are using TypeScript you will be required to use _snake_case_ style
8
9
to define the API parameters instead of _camelCase_.
9
10
10
-
Other than the types for the surface API, the client offers the types for every
11
-
request method, via the `RequestParams`, if you need the types for a search
12
-
request for instance, you can access them via `RequestParams.Search`.
13
-
Every API that supports a body, accepts a
14
-
https://www.typescriptlang.org/docs/handbook/generics.html[generics] which
15
-
represents the type of the request body, if you don't configure anything, it
16
-
will default to `RequestBody`. +
17
-
`RequestBody`, along with `RequestNDBody` and `ResponseBody` are defined inside the client, and it looks like this:
11
+
By default event API uses https://www.typescriptlang.org/docs/handbook/generics.html[generics] to specify the requets and response bodies and the `meta.context`. Currently we can't provide those definitions, but we are working to improve this situation.
12
+
13
+
You can't fid a partial definition of the request types by importing `RequestParams`, which it is used by default in the client and accepts a body (when needed) as a generic to provide a better specification.
14
+
15
+
The body defaults to `RequestBody` and `RequestNDBody`, which are defined as follows:
16
+
18
17
[source,ts]
19
18
----
20
-
type RequestBody<T = Record<string, any>> = T | string | Buffer | ReadableStream
21
-
type RequestNDBody<T = Record<string, any>[]> = T | string[] | Buffer | ReadableStream
22
-
type ResponseBody<T = Record<string, any>> = T | string | boolean | ReadableStream
19
+
type RequestBody<T = Record<string, any>> = T | string | Buffer | ReadableStream
20
+
type RequestNDBody<T = Record<string, any>[]> = T | string | string[] | Buffer | ReadableStream
23
21
----
24
22
25
-
For example:
23
+
You can specify the response and request body in each API as follows:
26
24
27
25
[source,ts]
28
26
----
29
-
import { RequestParams } from '@elastic/elasticsearch'
0 commit comments