-
Notifications
You must be signed in to change notification settings - Fork 138
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
Plural Keyv.get([])
types are incorrect, or Store.getMany()
returns incorrect type
#720
Comments
Hi @trevor-scheer - would love to see a code sample on how to reproduce this (it can be really simple) and also what you would like to see. Thanks! |
Sure thing. Here's a codesandbox where my runtime is in conflict with the types (there's a sneaky I think that I'll open a PR with my suggestion. I think just making the overloaded |
Hi @trevor-scheer 👋 Sorry for the delay on this as I am doing the research since this could be considered a major breaking change. I will be reviewing it more this week as the initial plan on getMany was to always return an It might make more sense to always return an array but fix the Store to convey this change or make sure at Keyv to always return the array even if the store returns undefined we would replace it with an |
@jaredwray no worries on the timing. Right now the typings aren't inline with the runtime. Aligning the types to the reality, while "introducing" new TS errors for users on upgrade, would help them to address currently invalid assumptions in their code - i.e. it would surface existing bugs. For that reason I'd consider the PR I've opened to be a bug fix, since there's a bug in the types. Changing the behavior of either In any case, I think I've fully convinced myself that my PR should land as a patch. I'd be happy to put some more thought into the future API with you if you're interested in any runtime changes - though I think the current state is reasonable. |
@trevor-scheer - just getting back to this and do agree that this should be a patch. Do you want to update your PR to a working state and we will get this merged in? |
@trevor-scheer - I just pulled this down and it looks like changing the Just tested it on a couple major projects such as GOT and Apollo and it will cause a big break. What would it take to move to being based on the standard instead? |
@jaredwray I think there might be a bit of a misunderstanding here or we actually disagree on whether or not this is a breaking change. I don't see how this could be a big break for anyone consuming this package, given that it's only a typings change. Yes - for typescript consumers, there will be new errors upon upgrading The alternative of changing |
Yeah, it seems to me that if the plan for fixing this is to change |
Wouldn't it be possible to just declare this a runtime bug, not a types bug, and make a small change to default to That way the types won't break the many millions of dependents (via I don't know this repo, but maybe this line: keyv/packages/keyv/src/index.js Line 148 in ed9f487
could be changed something like: return Promise.resolve()
- .then(() => isArray ? store.getMany(keyPrefixed) : store.get(keyPrefixed))
+ .then(() => isArray ? store.getMany(keyPrefixed).then(result => result || []) : store.get(keyPrefixed))
.then(data => (typeof data === 'string') ? this.opts.deserialize(data) : (this.opts.compression ? this.opts.deserialize(data) : data)) |
Hi @trevor-scheer - I am going to close this in favor of the work we are doing on Keyv v5 as that will have a more defined type. Please follow along here: #868 |
Thanks @jaredwray, looking forward to v5! |
Additional context: apollographql/apollo-utils#260
Describe the bug
The "plural"
Keyv.get([])
overload is expected to returnPromise<Array<V | undefined>>
based on the typings. However, you can see in my PR that when aStore.getMany()
returnsundefined
, thenundefined
is returned byKeyv.get([])
.Should
Store.getMany()
be required to always return an array (I think no,undefined
seems semantically useful in the error case, maybe)? Or should theKeyv.get([])
types be updated to include the possibility ofundefined
so we know to handle that case?How To Reproduce (best to provide workable code or tests!)
Reproduction available in the linked PR.
The initial commit demonstrating bad behavior might be more interesting:
apollographql/apollo-utils@6062106
The text was updated successfully, but these errors were encountered: