Skip to content

Inability to import your official types e.g. IndexRequest, SearchResponse etc. #2612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jdickie opened this issue Feb 10, 2025 · 2 comments
Closed

Comments

@jdickie
Copy link

jdickie commented Feb 10, 2025

Question

Background

We operate a project that uses Typescript, Lambda and Elasticsearch. We've been using your elasticsearch package for some time, and recently I have been working to upgrade our local version to your latest - 8.17.0 from 8.15.1.

The problem

We have declarations like the following that no longer work (Typescript throws a compiler error):

import { IndexRequest, SearchResponse } from '@elastic/elasticsearch/lib/api/types';

// ...

const params: IndexRequest<AuthorizedClient> = {
            index: AUTH_DOCUMENT_INDEX,
            id: client.id,
            document: client,
        };

The above used to be fine with tsc, but now it throws an error:

error TS2307: Cannot find module '@elastic/elasticsearch/lib/api/types' or its corresponding type declarations.

Any reason this works in 8.15.1 but not in 8.17.0? Can we still import types or no?

Things tried

  • Using @types/elasticsearch, this works to bring in types, but that package is missing IndexRequest among other types and at least the SearchResponse type is incompatible with the official @elastic/elasticsearch exported API.
@JoshMock
Copy link
Member

JoshMock commented Feb 10, 2025

Not immediately obvious, but it is mentioned in the docs that the appropriate way to import request/response types is via the estypes value exported from the index:

import { estypes } from '@elastic/elasticsearch'

It probably worked in the recent past, but as I've been preparing this library for full ESM support, importing nested files that are not specified in the package.json may fail. I've got a plan to improve that experience, but it hasn't reached the top of my priority list.

@jdickie
Copy link
Author

jdickie commented Feb 10, 2025

That works thus far! ❤ Thank you! To be clear, I went with:

import { estypes } from '@elastic/elasticsearch'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants