Skip to content

Replace get<Raw>(...) with an overload #805

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

Merged
merged 1 commit into from
Jul 12, 2023
Merged

Conversation

mmkal
Copy link
Contributor

@mmkal mmkal commented May 10, 2023

One overload with options?: { raw?: false } and one with options: { raw: true } allows being specific about the return type for each.

So, the behavior is unchanged but it becomes easier for external libraries to write an interface with a correct partial implementation.

My use-case: I'm working on a library that expects a keyv-like object passed in. The user is allowed to pass in a different implementation, as long as the basic get, set and delete exist. But they don't need to provide an implementation for the { raw: true } variant. So, I'm trying to write an interface that corresponds to that, which new Keyv<string>(...) conforms to. This is hard/impossible to do without some as any hacks right now, but the change in this commit makes it possible.

I tried this by modifying node_modules on my project and it worked, but I'm hoping CI will flag any type errors I missed. Will check the boxes below once green.

TypeScript playground demonstrating the problem.

Please check if the PR fulfills these requirements

  • Followed the Contributing guidelines.
  • [ ] Tests for the changes have been added (for bug fixes/features) with 100% code coverage. N/A - type-only change
  • [ ] Docs have been added / updated (for bug fixes / features) N/A - type-only change

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Change to the implementation detail of the get type. No change in how get can be used, just makes it easier to create a simple partial interface that Keyv conforms to.

One overload with `options?: { raw?: false }` and one with `options: { raw: true }` allows being specific about the return type for each.

So, the behavior is unchanged but it becomes easier for external libraries to write an interface with a correct *partial* implementation.

My use-case: I'm working on a library that expects a keyv-like object passed in. The user is allowed to pass in a different implementation, as long as the basic `get`, `set` and `delete` exist. But they don't need to provide an implementation for the `{ raw: true }` variant. So, I'm trying to write an interface that corresponds to that, which `new Keyv<string>(...)` conforms to. This is hard/impossible to do without some `as any` hacks right now, but the change in this commit makes it possible.

Signed-off-by: Misha Kaletsky <[email protected]>
@codecov
Copy link

codecov bot commented May 10, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (ed9f487) 100.00% compared to head (864bb46) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #805   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         2461      2461           
  Branches       176       176           
=========================================
  Hits          2461      2461           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jaredwray jaredwray merged commit a064ecf into jaredwray:main Jul 12, 2023
@jaredwray
Copy link
Owner

@mmkal - thanks so much for this and we will be planning to push this live in the next couple weeks.

@mmkal mmkal deleted the patch-1 branch October 18, 2023 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants