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

Incorrect type for save in Store<T> #22

Closed
matheus23 opened this issue Sep 15, 2021 · 2 comments · Fixed by #24
Closed

Incorrect type for save in Store<T> #22

matheus23 opened this issue Sep 15, 2021 · 2 comments · Fixed by #24
Labels

Comments

@matheus23
Copy link

In this example, save is defined as an async function:

save: async (value) => {
// Save some arbitrary object to our store. When IAMap uses this it's saving a plain object
// representation of an IAMap node. See IAMap#toSerializable() for information on that form.
store.stats.saves++
const { cid, bytes } = await store.encode(value)
await store.backingDb.put(cid.toString(), bytes)
return cid
},

But the return type for save is supposed to be T, not Promise<T>:

iamap/interface.ts

Lines 1 to 7 in 06d4402

// store using a link type `T`
export interface Store<T> {
save(node: any): T,
load(id: T): any,
isLink(link: T): boolean,
isEqual(link1: T, link2: T): boolean,
}

So I think the type should be changed to either Promise<T> or T | Promise<T>.

@rvagg
Copy link
Owner

rvagg commented Sep 16, 2021

good catch, should be fixed in a patch release, thanks

github-actions bot pushed a commit that referenced this issue Sep 16, 2021
### [2.0.6](v2.0.5...v2.0.6) (2021-09-16)

### Bug Fixes

* correctly type save() and load() types as async ([da03346](da03346)), closes [#22](#22)
@github-actions
Copy link

🎉 This issue has been resolved in version 2.0.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

2 participants