refactor(RouterProvider, chromeStorage, useContextMenuData): 更新存储获取逻辑以移除默认值参数

- 在 RouterProvider 和 useContextMenuData 中更新对 storageUtil.get 的调用,移除默认值参数,简化逻辑。
- 修改 chromeStorage 中的 get 方法签名,确保在没有默认值时返回可选类型,并添加相应的单元测试以验证类型推断。
This commit is contained in:
雨霖铃
2026-06-19 20:47:43 +08:00
parent ed383dd319
commit 47d74f999e
4 changed files with 26 additions and 9 deletions
+15 -1
View File
@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest';
import { describe, expect, it, expectTypeOf } from 'vitest';
import { storageUtil } from '@/utils/chromeStorage';
describe('chromeStorage', () => {
@@ -75,6 +75,20 @@ describe('chromeStorage', () => {
});
});
describe('get 类型签名', () => {
it('无默认值时应推断为可选返回类型', () => {
const getWithoutDefault = () => storageUtil.get('app/theme');
expectTypeOf<ReturnType<typeof getWithoutDefault>>().toEqualTypeOf<
Promise<string | undefined>
>();
});
it('有默认值时应推断为确定返回类型', () => {
const getWithDefault = () => storageUtil.get('app/theme', 'light');
expectTypeOf<ReturnType<typeof getWithDefault>>().toEqualTypeOf<Promise<string>>();
});
});
describe('set', () => {
it('应该成功设置字符串值', async () => {
(chrome.storage.local.set as any).mockResolvedValue(undefined);