Expose the new type definition along with the current one (#1440)

This commit is contained in:
Tomas Della Vedova
2021-04-07 14:08:18 +02:00
committed by delvedor
parent cba4affb82
commit e198511327
20 changed files with 4505 additions and 594 deletions

View File

@ -19,7 +19,7 @@
import { expectType } from 'tsd'
import { TransportRequestCallback, Context } from '../../lib/Transport'
import { Client, ApiError, estypes } from '../../'
import { Client, ApiError } from '../../'
const client = new Client({
node: 'http://localhost:9200'
@ -29,15 +29,23 @@ const client = new Client({
{
const response = await client.cat.count({ index: 'test' })
expectType<estypes.CatCountResponse>(response.body)
expectType<Record<string, any>>(response.body)
expectType<Context>(response.meta.context)
}
// Define the context (promise style)
// Define only the response body (promise style)
{
const response = await client.cat.count<string>({ index: 'test' })
expectType<estypes.CatCountResponse>(response.body)
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<string>(response.meta.context)
}
@ -45,18 +53,28 @@ const client = new Client({
{
const result = client.cat.count({ index: 'test' }, (err, response) => {
expectType<ApiError>(err)
expectType<estypes.CatCountResponse>(response.body)
expectType<Record<string, any>>(response.body)
expectType<Context>(response.meta.context)
})
expectType<TransportRequestCallback>(result)
}
// Define the context (callback style)
// Define only the response body (callback style)
{
const result = client.cat.count<string>({ index: 'test' }, (err, response) => {
expectType<ApiError>(err)
expectType<estypes.CatCountResponse>(response.body)
expectType<string>(response.meta.context)
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<TransportRequestCallback>(result)
}