diff --git a/packages/storage/src/__tests__/index.test.ts b/packages/storage/src/__tests__/index.test.ts index 3492781b0..faa1bc5a8 100644 --- a/packages/storage/src/__tests__/index.test.ts +++ b/packages/storage/src/__tests__/index.test.ts @@ -1281,6 +1281,19 @@ describe('Storage Utils', () => { it('should define a nullable value when options are not passed', () => { const item = storage.defineItem(`local:test`); expectTypeOf(item).toEqualTypeOf>(); + + const item2 = storage.defineItem(`local:test`, {}); + expectTypeOf(item2).toEqualTypeOf>(); + + const item3 = storage.defineItem(`local:test`, { + fallback: undefined, + }); + expectTypeOf(item3).toEqualTypeOf>(); + + const item4 = storage.defineItem(`local:test`, { + defaultValue: undefined, + }); + expectTypeOf(item4).toEqualTypeOf>(); }); it('should define a non-null value when options are passed with a nullish default value', () => { @@ -1288,6 +1301,11 @@ describe('Storage Utils', () => { defaultValue: 123, }); expectTypeOf(item).toEqualTypeOf>(); + + const item2 = storage.defineItem(`local:test`, { + fallback: 123, + }); + expectTypeOf(item2).toEqualTypeOf>(); }); it('should define a nullable value when options are passed with null default value', () => { diff --git a/packages/storage/src/index.ts b/packages/storage/src/index.ts index 0b0ced7c6..fe2d66c35 100644 --- a/packages/storage/src/index.ts +++ b/packages/storage/src/index.ts @@ -750,8 +750,16 @@ export interface WxtStorage { ): WxtStorageItem; defineItem = {}>( key: StorageItemKey, - options: WxtStorageItemOptions, + options: WxtStorageItemOptions & { fallback: TValue }, + ): WxtStorageItem; + defineItem = {}>( + key: StorageItemKey, + options: WxtStorageItemOptions & { defaultValue: TValue }, ): WxtStorageItem; + defineItem = {}>( + key: StorageItemKey, + options: WxtStorageItemOptions, + ): WxtStorageItem; } interface WxtStorageDriver {