New type definitions (#1358)
This commit is contained in:
committed by
delvedor
parent
f7edb80df7
commit
f138b077e3
@ -19,7 +19,7 @@
|
||||
|
||||
import { expectType } from 'tsd'
|
||||
import { TransportRequestCallback, Context } from '../../lib/Transport'
|
||||
import { Client, ApiError } from '../../'
|
||||
import { Client, ApiError, estypes } from '../../'
|
||||
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200'
|
||||
@ -29,23 +29,15 @@ const client = new Client({
|
||||
{
|
||||
const response = await client.cat.count({ index: 'test' })
|
||||
|
||||
expectType<Record<string, any>>(response.body)
|
||||
expectType<estypes.CatCountResponse>(response.body)
|
||||
expectType<Context>(response.meta.context)
|
||||
}
|
||||
|
||||
// Define only the response body (promise style)
|
||||
// Define the context (promise style)
|
||||
{
|
||||
const response = await client.cat.count<string>({ index: 'test' })
|
||||
|
||||
expectType<string>(response.body)
|
||||
expectType<Context>(response.meta.context)
|
||||
}
|
||||
|
||||
// Define response body and the context (promise style)
|
||||
{
|
||||
const response = await client.cat.count<string, string>({ index: 'test' })
|
||||
|
||||
expectType<string>(response.body)
|
||||
expectType<estypes.CatCountResponse>(response.body)
|
||||
expectType<string>(response.meta.context)
|
||||
}
|
||||
|
||||
@ -53,28 +45,18 @@ const client = new Client({
|
||||
{
|
||||
const result = client.cat.count({ index: 'test' }, (err, response) => {
|
||||
expectType<ApiError>(err)
|
||||
expectType<Record<string, any>>(response.body)
|
||||
expectType<estypes.CatCountResponse>(response.body)
|
||||
expectType<Context>(response.meta.context)
|
||||
})
|
||||
expectType<TransportRequestCallback>(result)
|
||||
}
|
||||
|
||||
// Define only the response body (callback style)
|
||||
// Define the context (callback style)
|
||||
{
|
||||
const result = client.cat.count<string>({ index: 'test' }, (err, response) => {
|
||||
expectType<ApiError>(err)
|
||||
expectType<string>(response.body)
|
||||
expectType<Context>(response.meta.context)
|
||||
})
|
||||
expectType<TransportRequestCallback>(result)
|
||||
}
|
||||
|
||||
// Define response body and the context (callback style)
|
||||
{
|
||||
const result = client.cat.count<string, Context>({ index: 'test' }, (err, response) => {
|
||||
expectType<ApiError>(err)
|
||||
expectType<string>(response.body)
|
||||
expectType<Context>(response.meta.context)
|
||||
expectType<estypes.CatCountResponse>(response.body)
|
||||
expectType<string>(response.meta.context)
|
||||
})
|
||||
expectType<TransportRequestCallback>(result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user