File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -1315,6 +1315,18 @@ describe('Storage Utils', () => {
13151315 } ) ;
13161316 expectTypeOf ( item ) . toEqualTypeOf < WxtStorageItem < number | null , { } > > ( ) ;
13171317 } ) ;
1318+
1319+ it ( 'should define a non-null value when options are passed with a non-null init function' , ( ) => {
1320+ const item = storage . defineItem ( `local:test` , {
1321+ init : ( ) => 123 ,
1322+ } ) ;
1323+ expectTypeOf ( item ) . toEqualTypeOf < WxtStorageItem < number , { } > > ( ) ;
1324+
1325+ const item2 = storage . defineItem ( `local:test` , {
1326+ init : ( ) => Promise . resolve ( 123 ) ,
1327+ } ) ;
1328+ expectTypeOf ( item2 ) . toEqualTypeOf < WxtStorageItem < number , { } > > ( ) ;
1329+ } ) ;
13181330 } ) ;
13191331 } ) ;
13201332
Original file line number Diff line number Diff line change @@ -752,6 +752,12 @@ export interface WxtStorage {
752752 key : StorageItemKey ,
753753 options : WxtStorageItemOptions < TValue > & { defaultValue : TValue } ,
754754 ) : WxtStorageItem < TValue , TMetadata > ;
755+ defineItem < TValue , TMetadata extends Record < string , unknown > = { } > (
756+ key : StorageItemKey ,
757+ options : WxtStorageItemOptions < TValue > & {
758+ init : ( ) => TValue | Promise < TValue > ;
759+ } ,
760+ ) : WxtStorageItem < TValue , TMetadata > ;
755761 defineItem < TValue , TMetadata extends Record < string , unknown > = { } > (
756762 key : StorageItemKey ,
757763 options : WxtStorageItemOptions < TValue > ,
You can’t perform that action at this time.
0 commit comments