Skip to content
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

Fix const enum issues #1593

Merged
merged 3 commits into from
Oct 17, 2023
Merged

Fix const enum issues #1593

merged 3 commits into from
Oct 17, 2023

Conversation

jonespen
Copy link
Contributor

Pull Request

Related issue

Fixes #1588

What does this PR do?

const enum is not really suited for libraries (ref https://youtu.be/jjMbPt_H3RQ?feature=shared&t=249 and https://www.typescriptlang.org/docs/handbook/enums.html#const-enum-pitfalls) and cause issues in typescript projects with isolatedModules: true (like Next.js). Instead, regular objects can be used (like done in #1350) with as const to make them type safe.

About the as readonly string[] in cfcda4f, this could probably have been solved by a type guard as well, but I opted for the type cast option instead to avoid runtime code changes.

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Copy link
Member

@brunoocasali brunoocasali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for raising this PR @jonespen, and for your first contribution here! 🎉

bors merge

meili-bors bot added a commit that referenced this pull request Oct 17, 2023
1593: Fix const enum issues r=brunoocasali a=jonespen

# Pull Request

## Related issue
Fixes #1588

## What does this PR do?
`const enum` is not really suited for libraries (ref https://youtu.be/jjMbPt_H3RQ?feature=shared&t=249 and https://www.typescriptlang.org/docs/handbook/enums.html#const-enum-pitfalls) and cause issues in typescript projects with `isolatedModules: true` (like Next.js). Instead, regular objects can be used (like done in #1350) with `as const` to make them type safe. 

About the `as readonly string[]` in cfcda4f, this could probably have been solved by a type guard as well, but I opted for the type cast option instead to avoid runtime code changes. 

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: Jon Espen Kvisler <jonespen@gmail.com>
@brunoocasali brunoocasali added the enhancement New feature or request label Oct 17, 2023
@codecov
Copy link

codecov bot commented Oct 17, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (8a74e35) 97.42% compared to head (cfcda4f) 97.43%.
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1593      +/-   ##
==========================================
+ Coverage   97.42%   97.43%   +0.01%     
==========================================
  Files          22       22              
  Lines         814      819       +5     
  Branches      109      109              
==========================================
+ Hits          793      798       +5     
  Misses         20       20              
  Partials        1        1              
Files Coverage Δ
src/task.ts 100.00% <ø> (ø)
src/types/types.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@meili-bors
Copy link
Contributor

meili-bors bot commented Oct 17, 2023

This PR was included in a batch that successfully built, but then failed to merge into main. It will not be retried.

Additional information:

{"message":"At least 1 approving review is required by reviewers with write access.","documentation_url":"https://docs.github.com/articles/about-protected-branches"}

Copy link
Member

@brunoocasali brunoocasali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors merge

@meili-bors
Copy link
Contributor

meili-bors bot commented Oct 17, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MatchingStrategies type issues
2 participants