Clarify type generics in docs

Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Eric Peterson
2023-01-10 13:45:56 +01:00
parent 0fcbe29c6b
commit ec2d3935b3
+14 -6
View File
@@ -136,14 +136,22 @@ import { isOpenSearchCompatible } from '@backstage/plugin-search-backend-module-
import { Client as ElasticClient } from '@elastic/elasticsearch';
import { Client as OpenSearchClient } from '@opensearch-project/opensearch';
const client = searchEngine.newClient(options => {
// In reality, you would only import / instantiate one of the following, but
// for illustrative purposes, here are both:
if (isOpenSearchCompatible(options)) {
return new OpenSearchClient(options);
} else {
// Return an Elasticsearch client
const esClient = searchEngine.newClient<ElasticClient>(options => {
if (!isOpenSearchCompatible(options)) {
return new ElasticClient(options);
}
throw new Error('Incompatible options');
});
// Return an OpenSearch client
const osClient = searchEngine.newClient<OpenSearchClient>(options => {
if (isOpenSearchCompatible(options)) {
return new OpenSearchClient(options);
}
throw new Error('Incompatible options');
});
```