Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 96cf923

Browse files
committed
fixed type errors
1 parent 6cd5162 commit 96cf923

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

packages/core/src/collection/group/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ export class Group<
315315
* @public
316316
* @param config - Configuration object
317317
*/
318-
public persist(config: GroupPersistConfigInterface = {}): this {
318+
public persist(
319+
config: GroupPersistConfigInterface<Array<ItemKey>> = {}
320+
): this {
319321
config = defineConfig(config, {
320322
key: this._key,
321323
followCollectionPersistKeyPattern: true,
@@ -480,8 +482,8 @@ export interface GroupConfigInterface {
480482
isPlaceholder?: boolean;
481483
}
482484

483-
export interface GroupPersistConfigInterface
484-
extends CreateStatePersistentConfigInterface {
485+
export interface GroupPersistConfigInterface<ValueType = any>
486+
extends CreateStatePersistentConfigInterface<ValueType> {
485487
/**
486488
* Whether to format the specified Storage key following the Collection Group Storage key pattern.
487489
* `_${collectionKey}_group_${groupKey}`

packages/core/src/collection/item.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from '../state';
88
import { Collection, DefaultItem } from './collection';
99
import { SelectorKey } from './selector';
10-
import { PersistentKey } from '../storages';
1110
import { CollectionPersistent } from './collection.persistent';
1211

1312
export class Item<
@@ -96,7 +95,7 @@ export class Item<
9695
* @public
9796
* @param config - Configuration object
9897
*/
99-
public persist(config: ItemPersistConfigInterface = {}): this {
98+
public persist(config: ItemPersistConfigInterface<DataType> = {}): this {
10099
config = defineConfig(config, {
101100
key: this._key,
102101
followCollectionPersistKeyPattern: true,
@@ -142,8 +141,8 @@ export interface ItemConfigInterface {
142141
isPlaceholder?: boolean;
143142
}
144143

145-
export interface ItemPersistConfigInterface
146-
extends CreateStatePersistentConfigInterface {
144+
export interface ItemPersistConfigInterface<DataType = any>
145+
extends CreateStatePersistentConfigInterface<DataType> {
147146
/**
148147
* Whether to format the specified Storage key following the Collection Item Storage key pattern.
149148
* `_${collectionKey}_item_${itemKey}`

packages/core/src/state/state.enhanced.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,9 @@ export class EnhancedState<ValueType = any> extends State<ValueType> {
424424
* @public
425425
* @param config - Configuration object
426426
*/
427-
public persist(config: CreateStatePersistentConfigInterface = {}): this {
427+
public persist(
428+
config: CreateStatePersistentConfigInterface<ValueType> = {}
429+
): this {
428430
config = defineConfig(config, {
429431
key: this._key,
430432
});

packages/core/src/state/state.persistent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from '@agile-ts/utils';
1+
import { copy, defineConfig } from '@agile-ts/utils';
22
import {
33
CreatePersistentConfigInterface,
44
getSharedStorageManager,
@@ -27,7 +27,7 @@ export class StatePersistent<ValueType = any> extends Persistent {
2727
*/
2828
constructor(
2929
state: EnhancedState<ValueType>,
30-
config: CreateStatePersistentConfigInterface = {}
30+
config: CreateStatePersistentConfigInterface<ValueType> = {}
3131
) {
3232
super(state.agileInstance(), {
3333
loadValue: false,
@@ -203,7 +203,7 @@ export class StatePersistent<ValueType = any> extends Persistent {
203203
getSharedStorageManager()?.set(
204204
storageItemKey,
205205
this.onSave != null
206-
? this.onSave(this.state().getPersistableValue())
206+
? this.onSave(copy(this.state().getPersistableValue()))
207207
: this.state().getPersistableValue(),
208208
this.storageKeys
209209
);

0 commit comments

Comments
 (0)