Co-authored-by: Aaron <aaronklinker1@gmail.com>
This commit is contained in:
@@ -903,5 +903,24 @@ describe('Storage Utils', () => {
|
||||
// @ts-expect-error
|
||||
await storage.getItem('loca:test').catch(() => {});
|
||||
});
|
||||
|
||||
it('should return a nullable type when getItem is called without a fallback', async () => {
|
||||
const res = await storage.getItem<string>('local:test');
|
||||
expectTypeOf(res).toBeNullable();
|
||||
});
|
||||
|
||||
it('should return a non-null type when getItem is called with a fallback', async () => {
|
||||
const res = await storage.getItem('local:test', {
|
||||
fallback: 'test',
|
||||
});
|
||||
expectTypeOf(res).not.toBeNullable();
|
||||
});
|
||||
|
||||
it('should return a non-null type when getItem is called with a fallback and the first type parameter is passed', async () => {
|
||||
const res = await storage.getItem<string>('local:test', {
|
||||
fallback: 'test',
|
||||
});
|
||||
expectTypeOf(res).not.toBeNullable();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -461,7 +461,16 @@ export interface WxtStorage {
|
||||
* @example
|
||||
* await storage.getItem<number>("local:installDate");
|
||||
*/
|
||||
getItem<T>(key: StorageItemKey, opts?: GetItemOptions<T>): Promise<T | null>;
|
||||
getItem<TValue>(
|
||||
key: StorageItemKey,
|
||||
opts: GetItemOptions<TValue> & { fallback: TValue },
|
||||
): Promise<TValue>;
|
||||
|
||||
getItem<TValue>(
|
||||
key: StorageItemKey,
|
||||
opts?: GetItemOptions<TValue>,
|
||||
): Promise<TValue | null>;
|
||||
|
||||
/**
|
||||
* Get multiple items from storage. The return order is guaranteed to be the same as the order
|
||||
* requested.
|
||||
|
||||
Reference in New Issue
Block a user