* Updated types generation script * Refactored api method definitions * Updated test - Removed old test code - Added tsd dev dependency - Rewritten test with tsd * Removed unused dependencies * Fixed definition * Updated test * Updated docs * Improved events type definitions * Updated test * Minor fixes in the type definitons * More type test * Improved Transport type definitions * Updated test * Addressed comments * Code generation * Use RequestBody, Response and Context everywhere, also default Context to unknown * Updated test * body -> hasBody * Fixed conflicts * Updated code generation * Improved request body type definition * Updated code generation * Use BodyType for both request and reponses generics - Use extends for defining the RequestBody generic to force the user following the same shape. - BodyType and NDBodyType now accepts a generics to allow injecting more specific types in the future * API generation * Updated test * Updated docs * Use BodyType also in ReponseError * Removed useless client generics * Renamed generics and types - prefixed all generics with a T - BodyType => RequestBody - NDBodyType => RequestNDBody - Added ResponseBody * Updated test * Updated docs * Test ResponseBody as well * Simplify overloads * API generation * Updated test * Updated error types
36 lines
946 B
TypeScript
36 lines
946 B
TypeScript
// Licensed to Elasticsearch B.V under one or more agreements.
|
|
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
|
// See the LICENSE file in the project root for more information
|
|
|
|
import { expectType } from 'tsd'
|
|
import { ResponseBody } from '../../lib/Transport'
|
|
import { Client } from '../../'
|
|
|
|
const client = new Client({
|
|
node: 'http://localhost:9200'
|
|
})
|
|
|
|
// No generics
|
|
{
|
|
const response = await client.cat.count({ index: 'test' })
|
|
|
|
expectType<ResponseBody>(response.body)
|
|
expectType<unknown>(response.meta.context)
|
|
}
|
|
|
|
// Define only the request body
|
|
{
|
|
const response = await client.cat.count<string>({ index: 'test' })
|
|
|
|
expectType<string>(response.body)
|
|
expectType<unknown>(response.meta.context)
|
|
}
|
|
|
|
// Define request body and the context
|
|
{
|
|
const response = await client.cat.count<string, string>({ index: 'test' })
|
|
|
|
expectType<string>(response.body)
|
|
expectType<string>(response.meta.context)
|
|
}
|