forked from flow-typed/flow-typed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add libdefs for idb-keyval (flow-typed#1537)
- Loading branch information
1 parent
0b655a2
commit d679eea
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
definitions/npm/idb-keyval_v2.x.x/flow_v0.34.x-/idb-keyval_v2.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Derived from TS typings at https://github.com/jakearchibald/idb-keyval/blob/b49b4e9fbf2f5deb63598f9cf0d9899d2f89dc95/typings.d.ts | ||
|
||
declare module 'idb-keyval' { | ||
declare interface IDBKeyVal<Key> { | ||
/** Add a new value or update an existing one */ | ||
set<Value>(key: Key, value: Value): Promise<void>, | ||
|
||
/** Get a value by key */ | ||
get<Value>(key: Key): Promise<Value>, | ||
|
||
/** Get all keys in the database */ | ||
keys(): Promise<Array<Key>>, | ||
|
||
/** Delete an entry in the database by key */ | ||
delete(key: Key): Promise<void>, | ||
|
||
/** Delete all entries in the database */ | ||
clear(): Promise<void>, | ||
} | ||
|
||
declare module.exports: IDBKeyVal<string>; | ||
} |
27 changes: 27 additions & 0 deletions
27
definitions/npm/idb-keyval_v2.x.x/test_idb-keyval-v2.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Derived from the usage docs: | ||
// https://github.com/jakearchibald/idb-keyval/blob/b49b4e9fbf2f5deb63598f9cf0d9899d2f89dc95/README.md | ||
|
||
import idbKeyval from 'idb-keyval'; | ||
|
||
async function test() { | ||
idbKeyval.set('hello', 'world'); | ||
(idbKeyval.set('foo', 'bar'): Promise<void>); | ||
|
||
await idbKeyval.set('baz', 'foo'); | ||
|
||
idbKeyval.set('hello', 'world') | ||
.then(() => console.log('It worked!')) | ||
.catch(err => console.log('It failed!', err)); | ||
|
||
idbKeyval.get('hello').then(val => (val: any)); | ||
|
||
const baz = await idbKeyval.get('baz'); | ||
|
||
// $ExpectError | ||
await idbKeyval.get(); | ||
|
||
idbKeyval.keys().then(keys => keys.map(k => k.toUpperCase())); | ||
|
||
idbKeyval.delete('hello'); | ||
idbKeyval.clear(); | ||
} |