Skip to content

Commit c62f228

Browse files
committed
MKT-1947 store types updates
1 parent 1d7bfc8 commit c62f228

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

__test__/store.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("Store", () => {
1515

1616
connection = { sendToParent: sendToParent };
1717
jest.spyOn(connection, "sendToParent");
18-
storeObj = new Store(connection);
18+
storeObj = new Store(connection as any);
1919
});
2020

2121
it("get", (done) => {
@@ -86,7 +86,9 @@ describe("Store", () => {
8686
});
8787

8888
it("errorCase", async () => {
89-
let storeWithError = new Store({ sendToParent: sendToParentError });
89+
let storeWithError = new Store({
90+
sendToParent: sendToParentError,
91+
} as any);
9092

9193
await expect(() => storeWithError.remove("a")).rejects.toThrow(
9294
"sample store error"

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/store.d.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
1+
import { GenericObjectType } from "./types/common.types";
2+
import postRobot from "post-robot";
13
/**
24
* Class used by an app to store your data in {@link external:localStorage}.
35
* @hideconstructor
46
*/
57
declare class Store {
6-
_connection: any;
7-
constructor(connection: any);
8+
_connection: typeof postRobot;
9+
constructor(connection: typeof postRobot);
810
/**
911
* Gets the value of key
1012
* @param {string} key Key of the stored data
1113
* @example extension.store.get('key').then((value) => console.log(value)) // will log value for the given key
1214
* @return {external:Promise}
1315
*/
14-
get(key: string): any;
16+
get(key: string): Promise<GenericObjectType>;
1517
/**
1618
* Gets an object with all the stored key-value pairs.
1719
* @example extension.store.getAll().then((obj) => obj)
1820
* @return {external:Promise}
1921
*/
20-
getAll(): any;
22+
getAll(): Promise<object>;
2123
/**
2224
* Sets the value of a key
2325
* @param {string} key Key of the stored data.
2426
* @param {*} value Data to be stored.
2527
* @example extension.store.set('key', 'value').then((success) => console.log(success)) // will log ‘true’ when value is set
2628
* @return {external:Promise}
2729
*/
28-
set(key: string, value: string): any;
30+
set(key: string, value: string): Promise<boolean>;
2931
/**
3032
* Removes the value of a key
3133
* @param {string} key Key of the data to be removed from the store
3234
* @example extension.store.remove('key').then((success) => console.log(success)) // will log ‘true’ when value is removed
3335
* @return {external:Promise}
3436
*/
35-
remove(key: string): any;
37+
remove(key: string): Promise<boolean>;
3638
/**
3739
* Clears all the stored data of an extension
3840
* @example extension.store.clear().then((success) => console.log(success)) // will log ‘true’ when values are cleared
3941
* @return {external:Promise}
4042
*/
41-
clear(): any;
43+
clear(): Promise<boolean>;
4244
}
4345
export default Store;
4446
//# sourceMappingURL=store.d.ts.map

dist/src/store.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/store.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import { GenericObjectType } from "./types/common.types";
12
import { onError } from "./utils/utils";
3+
import postRobot from "post-robot";
24

35
/**
46
* Class used by an app to store your data in {@link external:localStorage}.
57
* @hideconstructor
68
*/
79
class Store {
8-
_connection: any;
10+
_connection: typeof postRobot;
911

10-
constructor(connection: any) {
12+
constructor(connection: typeof postRobot) {
1113
this._connection = connection;
1214
}
1315
/**
@@ -22,7 +24,7 @@ class Store {
2224
}
2325
return this._connection
2426
.sendToParent("store", { action: "get", key })
25-
.then((event: { data: any }) => Promise.resolve(event.data))
27+
.then((event: { data: GenericObjectType }) => Promise.resolve(event.data))
2628
.catch(onError);
2729
}
2830

0 commit comments

Comments
 (0)