Replace get<Raw>(...)
with an overload
#805
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One overload with
options?: { raw?: false }
and one withoptions: { 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
anddelete
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, whichnew Keyv<string>(...)
conforms to. This is hard/impossible to do without someas 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
[ ] 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 changeWhat kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Change to the implementation detail of the
get
type. No change in howget
can be used, just makes it easier to create a simple partial interface thatKeyv
conforms to.