Browse Source

fix(@vben-core/preferences): type custom preference updates (#8374)

* fix(preferences): type custom preference updates

* style(preferences): order type test imports
pull/8383/head
俞可 · YU KE 3 weeks ago
committed by GitHub
parent
commit
0453faeb7d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/typed-custom-preferences-update.md
  2. 21
      packages/@core/preferences/__tests__/preferences-types.test.ts
  3. 6
      packages/@core/preferences/src/preferences.ts

5
.changeset/typed-custom-preferences-update.md

@ -0,0 +1,5 @@
---
'@vben-core/preferences': patch
---
fix(@vben-core/preferences): type custom preference updates

21
packages/@core/preferences/__tests__/preferences-types.test.ts

@ -0,0 +1,21 @@
import type { DeepPartial } from '@vben-core/typings';
import { describe, expectTypeOf, it } from 'vitest';
import { updateCustomPreferences } from '../src';
interface ProjectPreferences {
defaultTableSize: number;
tenantMode: 'multi' | 'single';
}
describe('custom preferences types', () => {
it('accepts a typed partial update', () => {
const updateProjectPreferences =
updateCustomPreferences<ProjectPreferences>;
expectTypeOf(updateProjectPreferences)
.parameter(0)
.toEqualTypeOf<DeepPartial<ProjectPreferences>>();
});
});

6
packages/@core/preferences/src/preferences.ts

@ -188,7 +188,11 @@ class PreferenceManager {
* 更新扩展偏好设置
* @param updates - 要更新的扩展偏好设置
*/
updateCustomPreferences = (updates: DeepPartial<object>) => {
updateCustomPreferences = <
TCustomPreferences extends object = CustomPreferencesRecord,
>(
updates: DeepPartial<TCustomPreferences>,
) => {
if (!this.customPreferencesExtension) {
return;
}

Loading…
Cancel
Save