From 605ec41191a3ccf2925226193852a1cfa41f70be Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 26 Dec 2024 13:42:08 +0000 Subject: [PATCH] fix(types): allow passing generic to untyped storage (#543) * fix(types): allow passing generic to untyped storage * chore: lint --- src/types.ts | 4 ++-- test/storage.test-d.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/types.ts b/src/types.ts index db443cc3..88c024df 100644 --- a/src/types.ts +++ b/src/types.ts @@ -91,10 +91,10 @@ export interface Storage { key: K, ops?: TransactionOptions ): Promise | null>; - getItem( + getItem>( key: string, opts?: TransactionOptions - ): Promise | null>; + ): Promise; /** @experimental */ getItems: ( diff --git a/test/storage.test-d.ts b/test/storage.test-d.ts index 010b62a4..4e7758bc 100644 --- a/test/storage.test-d.ts +++ b/test/storage.test-d.ts @@ -10,6 +10,14 @@ describe("types", () => { await storage.getItem("foo") ).toEqualTypeOf(); + expectTypeOf(await storage.getItem("foo")).toEqualTypeOf< + boolean | null + >(); + + expectTypeOf( + await storage.getItem<{ hello: string }>("foo") + ).toEqualTypeOf<{ hello: string } | null>(); + await storage.setItem("foo", "str"); await storage.set("bar", 1); await storage.removeItem("foo");