-
Notifications
You must be signed in to change notification settings - Fork 126
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
Add new types to package exports definition for ESM support #674
Conversation
Signed-off-by: Perttu Kärnä <[email protected]>
Is there a way to add a test for this so we don't break it in the future? |
Unfortunately I'm not sure if there is an easy way to test it - it probably requires setting up a child project with ESM and type checking. However, after having another look at the type definitions, I noticed the import { ApiResponse, opensearchtypes } from '@opensearch-project/opensearch'
import { Client } from '@opensearch-project/opensearch/api/new'
const client: Client
const response: ApiResponse<opensearchtypes.SearchResponse<TDocument>> = await client.search({ ... }) Technically we could export the new types via the root typings as well, but if they're still partially work in progress and opt-in, I'd keep them separate. |
@dblock @kavilla @AMoo-Miki not trying to rush anything, but happy to improve upon your request. I'd suggest we change this PR to export only the new types "./api/new": {
"types": "./api/new.d.ts"
} What do you think? |
@perttukarna Is this related to #670 (comment) ? |
@nhtruong yes and no. 😄 This won't solve the problem of having two different type definitions for the client, but merely makes the new type definitions available for certain project setups (TS + ESM in particular). |
@dblock @kavilla @AMoo-Miki can you take a look, please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAUK this looks correct, but 🤷♂️
Leaving to @nhtruong to decide and merge. |
Description
As of today, it's not possible to resolve the new typings with a TS project using ESM. With these changes, you can import types in ESM project, e.g.:
This is also backwards compatible with projects converting from TS + CommonJS to TS + ESM.
Issues Resolved
Closes #204
Check List
yarn run lint
doesn't show any errorsBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.