Skip to content

Commit fba4064

Browse files
committed
refactor(core): replace any types with unknown in useStorageState
Replace `any` with stricter `unknown` types in `SerializableGuard`, `isPlainObject`, `ensureSerializable`, and test serializer/deserializer to comply with the no-any coding standard.
1 parent da878b3 commit fba4064

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/hooks/useStorageState/useStorageState.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ describe('useStorageState', () => {
204204
});
205205

206206
it('should work with custom serializer and deserializer', async () => {
207-
const serializer = (value: any) =>
207+
const serializer = (value: string) =>
208208
['string', 'number', 'boolean'].includes(typeof value) ? value : JSON.stringify(value);
209-
const deserializer = (value: any) =>
209+
const deserializer = (value: string) =>
210210
/^(\d+)|(true|false)|([^[].*)|([^{].*)$/.test(value) ? value : JSON.parse(value);
211211

212212
const { result } = await renderHookSSR(() => useStorageState('test-key', { storage, serializer, deserializer }));

src/hooks/useStorageState/useStorageState.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type StorageStateOptionsWithSerializer<T> = StorageStateOptions<T> & {
2121
deserializer: (value: string) => Serializable<T>;
2222
};
2323

24-
type SerializableGuard<T extends readonly any[]> = T[0] extends any
24+
type SerializableGuard<T extends readonly unknown[]> = T[0] extends unknown
2525
? T
2626
: T[0] extends never
2727
? 'Received a non-serializable value'
@@ -33,7 +33,7 @@ const emitListeners = () => {
3333
listeners.forEach(listener => listener());
3434
};
3535

36-
function isPlainObject(value: unknown): value is Record<PropertyKey, any> {
36+
function isPlainObject(value: unknown): value is Record<PropertyKey, unknown> {
3737
if (typeof value !== 'object') {
3838
return false;
3939
}
@@ -49,7 +49,7 @@ function isPlainObject(value: unknown): value is Record<PropertyKey, any> {
4949
return Object.prototype.toString.call(value) === '[object Object]';
5050
}
5151

52-
const ensureSerializable = <T extends readonly any[]>(value: T): SerializableGuard<T> => {
52+
const ensureSerializable = <T extends readonly unknown[]>(value: T): SerializableGuard<T> => {
5353
if (
5454
value[0] != null &&
5555
!['string', 'number', 'boolean'].includes(typeof value[0]) &&

0 commit comments

Comments
 (0)