Skip to content

Commit 0d82c83

Browse files
committed
type: hooks full type v1.7.0
1 parent 7fb9c5e commit 0d82c83

File tree

2 files changed

+56
-52
lines changed

2 files changed

+56
-52
lines changed

packages/types/index.d.ts

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ declare interface CachedData<TData = any, TParams = any> {
1919

2020
export declare const clearUseRequestCache: (key?: string | string[]) => void;
2121

22-
export declare function createUseRequest<TData, TParams extends unknown[] = unknown[], PluginsOptions extends UseRequestPlugin<TData, TParams>[] = UseRequestPlugin<TData, TParams>[]>(service: UseRequestService<TData, TParams>, options?: UseRequestOptions<TData, TParams, PluginsOptions extends (infer P)[] ? P extends UseRequestPlugin<TData, TParams, infer R> ? R : any : any>, plugins?: PluginsOptions): useRequestResult<TData, TParams>;
23-
2422
declare interface DebounceOptions {
2523
/**
2624
* The number of milliseconds to delay.
@@ -96,13 +94,6 @@ declare class Fetch<TData, TParams extends unknown[] = any> {
9694
mutate(data?: TData | ((oldData?: TData) => TData | undefined)): void;
9795
}
9896

99-
declare type FetchType<TData, TParams> = Record<string | number, {
100-
data: TData | undefined;
101-
params: TParams;
102-
loading: boolean;
103-
key: string | number;
104-
}>;
105-
10697
declare interface IFuncUpdater<T> {
10798
(previousState?: T): T;
10899
}
@@ -143,8 +134,8 @@ declare enum ReadyState_2 {
143134
declare type Resolve = (value: any) => void;
144135

145136
declare type Size = {
146-
width: Ref<number>;
147-
height: Ref<number>;
137+
width: Readonly<Ref<number>>;
138+
height: Readonly<Ref<number>>;
148139
};
149140

150141
declare type StorageStateResultHasDefaultValue<T> = [
@@ -222,9 +213,9 @@ declare interface UseBooleanActions {
222213
toggle: () => void;
223214
}
224215

225-
declare type UseBooleanResult = [Ref<boolean>, UseBooleanActions];
216+
declare type UseBooleanResult = [Readonly<Ref<boolean>>, UseBooleanActions];
226217

227-
export declare function useCookieState(cookieKey: string, options?: UseCookieStateOptions): readonly [any, (newValue: UseCookieStateType | ((prevState: UseCookieStateType) => UseCookieStateType), newOptions?: Cookies.CookieAttributes) => void];
218+
export declare function useCookieState(cookieKey: string, options?: UseCookieStateOptions): readonly [Readonly<Ref<UseCookieStateType | (() => UseCookieStateType)>>, (newValue: UseCookieStateType | ((prevState: UseCookieStateType) => UseCookieStateType), newOptions?: Cookies.CookieAttributes) => void];
228219

229220
declare interface UseCookieStateOptions extends Cookies.CookieAttributes {
230221
defaultValue?: UseCookieStateType | (() => UseCookieStateType);
@@ -271,7 +262,7 @@ declare interface UseCounterOptions {
271262
max?: number;
272263
}
273264

274-
export declare function useDarkMode(): [ComputedRef<any>, (value?: unknown) => void];
265+
export declare function useDarkMode(): [ComputedRef<boolean>, (value?: unknown) => void];
275266

276267
export declare function useDebounce<T>(value: Ref<T>, options?: DebounceOptions): Ref<T>;
277268

@@ -414,7 +405,7 @@ declare type UseEventListenerOptions<T extends UseEventListenerTarget = UseEvent
414405

415406
declare type UseEventListenerTarget = BasicTarget<HTMLElement | Element | Window | Document>;
416407

417-
export declare function useExternal(path?: string | Ref<string>, options?: UseExternalOptions): Ref<UseExternalStatus>;
408+
export declare function useExternal(path?: string | Ref<string>, options?: UseExternalOptions): Readonly<Ref<UseExternalStatus>>;
418409

419410
declare interface UseExternalOptions {
420411
/**
@@ -440,15 +431,28 @@ export declare function useFetchs<TData, TParams>(service: UseRequestService<TDa
440431
}, self: {
441432
fetchKey?: (...args: ParamsType<TParams>) => string;
442433
}): {
443-
fetchs: Ref<FetchType<TData, TParams>>;
434+
fetchs: Readonly<Ref<{
435+
readonly [x: string]: {
436+
readonly data: DeepReadonly<TData> | undefined;
437+
readonly params: DeepReadonly<TParams>;
438+
readonly loading: boolean;
439+
readonly key: string | number;
440+
};
441+
readonly [x: number]: {
442+
readonly data: DeepReadonly<TData> | undefined;
443+
readonly params: DeepReadonly<TParams>;
444+
readonly loading: boolean;
445+
readonly key: string | number;
446+
};
447+
}>>;
444448
fetchRun: (...args: TParams extends any[] ? any[] : any) => void;
445449
};
446450

447451
export declare function useFocusWithin(
448452
/**
449453
* DOM element or ref
450454
*/
451-
target: BasicTarget, options?: UseFocusWithinOptions): Ref<boolean>;
455+
target: BasicTarget, options?: UseFocusWithinOptions): Readonly<Ref<boolean>>;
452456

453457
declare interface UseFocusWithinOptions {
454458
/**
@@ -473,7 +477,7 @@ declare interface UseFocusWithinOptions {
473477

474478
export declare function useFormatResult<TData, FData>(data: TData | Ref<TData>, formatResultCallback: (data: TData) => FData): ComputedRef<FData>;
475479

476-
export declare const useFullscreen: (target: BasicTarget, options?: UseFullscreenOptions) => readonly [Ref<boolean>, {
480+
export declare const useFullscreen: (target: BasicTarget, options?: UseFullscreenOptions) => readonly [Readonly<Ref<boolean>>, {
477481
readonly enterFullscreen: () => void;
478482
readonly exitFullscreen: () => void;
479483
readonly toggleFullscreen: () => void;
@@ -520,9 +524,9 @@ declare type UseInfiniteData = {
520524
};
521525

522526
export declare const useInfiniteScroll: <TData extends UseInfiniteData>(service: UseInfiniteService<TData>, options?: UseInfiniteScrollOptions<TData>) => {
523-
data: Ref<TData | undefined>;
524-
loading: ComputedRef<boolean>;
525-
loadingMore: Ref<boolean>;
527+
data: Readonly<Ref<TData | undefined>>;
528+
loading: Readonly<Ref<boolean>>;
529+
loadingMore: Readonly<Ref<boolean>>;
526530
noMore: ComputedRef<boolean>;
527531
loadMore: () => void;
528532
loadMoreAsync: () => Promise<TData> | undefined;
@@ -600,7 +604,7 @@ delay: Ref<number | undefined> | number | undefined, options?: {
600604
immediate?: boolean;
601605
}): void;
602606

603-
export declare function useInViewport(target: BasicTarget, options?: UseInViewportOptions): readonly [Ref<boolean | undefined>, Ref<number | undefined>];
607+
export declare function useInViewport(target: BasicTarget, options?: UseInViewportOptions): readonly [Readonly<Ref<boolean | undefined>>, Readonly<Ref<number | undefined>>];
604608

605609
declare interface UseInViewportOptions {
606610
/**
@@ -648,7 +652,7 @@ export declare const useLocalStorageState: <T>(key: string | Ref<string>, option
648652

649653
export declare function useLockFn<P extends any[], V>(fn: (...args: P) => Promise<V>): (...args: P) => Promise<V | undefined>;
650654

651-
export declare function useMap<K, T>(initialValue?: UseMapValue<K, T>): [Ref<Map<K, T>>, UseMapActions<K, T>];
655+
export declare function useMap<K, T>(initialValue?: UseMapValue<K, T>): [Readonly<Ref<Map<K, T>>>, UseMapActions<K, T>];
652656

653657
declare type UseMapActions<K, T> = {
654658
/**
@@ -713,22 +717,22 @@ values: {
713717
*/
714718
defaultValue: any): any;
715719

716-
export declare function useMouse(target?: BasicTarget): Ref<{
717-
screenX: number;
718-
screenY: number;
719-
clientX: number;
720-
clientY: number;
721-
pageX: number;
722-
pageY: number;
723-
elementX: number;
724-
elementY: number;
725-
elementH: number;
726-
elementW: number;
727-
elementPosX: number;
728-
elementPosY: number;
729-
}>;
730-
731-
export declare function useNetwork(): UseNetworkState;
720+
export declare function useMouse(target?: BasicTarget): Readonly<Ref<{
721+
readonly screenX: number;
722+
readonly screenY: number;
723+
readonly clientX: number;
724+
readonly clientY: number;
725+
readonly pageX: number;
726+
readonly pageY: number;
727+
readonly elementX: number;
728+
readonly elementY: number;
729+
readonly elementH: number;
730+
readonly elementW: number;
731+
readonly elementPosX: number;
732+
readonly elementPosY: number;
733+
}>>;
734+
735+
export declare function useNetwork(): Readonly<Ref<UseNetworkState>>;
732736

733737
declare interface UseNetworkState {
734738
since?: Date;
@@ -745,7 +749,7 @@ export declare function usePreview(md: Parameters<typeof createApp> | Ref<string
745749
container: Ref<Element | undefined>;
746750
};
747751

748-
export declare function usePrevious<T>(state: Ref<T> | ComputedRef<T>, shouldUpdate?: UsePreviousShouldUpdateFunc<T>): Ref<T | undefined>;
752+
export declare function usePrevious<T>(state: Ref<T> | ComputedRef<T>, shouldUpdate?: UsePreviousShouldUpdateFunc<T>): Readonly<Ref<DeepReadonly<T> | undefined>>;
749753

750754
declare type UsePreviousShouldUpdateFunc<T> = (prev: T | undefined, next: T) => boolean;
751755

@@ -913,7 +917,7 @@ declare type UseRequestOptions<TData, TParams extends unknown[], TPlugin> = {
913917
[K in keyof TPlugin]: TPlugin[K];
914918
};
915919

916-
export declare interface UseRequestPlugin<TData, TParams extends unknown[] = unknown[], TPlugin = any> {
920+
declare interface UseRequestPlugin<TData, TParams extends unknown[] = unknown[], TPlugin = any> {
917921
(fetchInstance: Fetch<TData, TParams>, options: UseRequestOptions<TData, TParams, TPlugin>): UseRequestPluginReturn<TData, TParams>;
918922
onInit?: (options: UseRequestOptions<TData, TParams, TPlugin>) => Partial<UseRequestFetchState<TData, TParams>>;
919923
}
@@ -939,19 +943,19 @@ declare interface useRequestResult<TData, TParams extends unknown[]> {
939943
/**
940944
* Is the service being executed.
941945
*/
942-
loading: Ref<boolean>;
946+
loading: Readonly<Ref<boolean>>;
943947
/**
944948
* Data returned by service.
945949
*/
946-
data: Ref<TData | undefined>;
950+
data: Readonly<Ref<TData | undefined>>;
947951
/**
948952
* Exception thrown by service.
949953
*/
950-
error: Ref<Error | undefined>;
954+
error: Readonly<Ref<Error | undefined>>;
951955
/**
952956
* params An array of parameters for the service being executed. For example, you triggered `run(1, 2, 3)`, then params is equal to `[1, 2, 3]`.
953957
*/
954-
params: Ref<TParams | []>;
958+
params: Readonly<Ref<TParams | []>>;
955959
/**
956960
* Ignore the current promise response.
957961
*/
@@ -980,15 +984,15 @@ declare interface useRequestResult<TData, TParams extends unknown[]> {
980984

981985
declare type UseRequestService<TData, TParams extends unknown[]> = (...args: TParams) => Promise<TData>;
982986

983-
export declare function useScroll(target?: UseScrollTarget, shouldUpdate?: UseScrollListenController): Ref<Position | undefined>;
987+
export declare function useScroll(target?: UseScrollTarget, shouldUpdate?: UseScrollListenController): Readonly<Ref<Position | undefined>>;
984988

985989
declare type UseScrollListenController = (val: Position) => boolean;
986990

987991
declare type UseScrollTarget = BasicTarget<Element | Document>;
988992

989993
export declare const useSessionStorageState: <T>(key: string | Ref<string>, options?: OptionsWithDefaultValue<T> | undefined) => StorageStateResultHasDefaultValue<T>;
990994

991-
export declare function useSet<T = any>(initialValue?: T[]): [Ref<Set<any>>, UseSetActions<T>];
995+
export declare function useSet<T = any>(initialValue?: T[]): [Readonly<Ref<Set<T>>>, UseSetActions<T>];
992996

993997
declare interface UseSetActions<T> {
994998
add: (value: T) => void;
@@ -1009,7 +1013,7 @@ declare type UseSetStateType<S> = S | (() => S) | Ref<S> | (() => Ref<S>);
10091013
*
10101014
* @param {dom id节点或者 ref句柄} target
10111015
*/
1012-
export declare function useSize(target: BasicTarget): Size | undefined;
1016+
export declare function useSize(target: BasicTarget): Size;
10131017

10141018
export declare function useThrottle<T>(value: Ref<T>, options?: UseThrottleOptions): Ref<any>;
10151019

@@ -1053,7 +1057,7 @@ declare type UseSetStateType<S> = S | (() => S) | Ref<S> | (() => Ref<S>);
10531057
export declare const useTrackedEffect: (effect: UseTrackedEffect, deps?: Ref[]) => void;
10541058

10551059
export declare function useUpdate(): {
1056-
update: Ref<{}>;
1060+
update: Readonly<Ref<{}>>;
10571061
setUpdate: () => void;
10581062
};
10591063

@@ -1100,11 +1104,11 @@ declare type UseSetStateType<S> = S | (() => S) | Ref<S> | (() => Ref<S>);
11001104
}
11011105

11021106
declare interface UseWebSocketResult {
1103-
latestMessage: Ref<WebSocketEventMap['message'] | undefined>;
1107+
latestMessage: Readonly<Ref<WebSocketEventMap['message'] | undefined>>;
11041108
sendMessage?: WebSocket['send'];
11051109
disconnect?: () => void;
11061110
connect?: () => void;
1107-
readyState: Ref<ReadyState_2>;
1111+
readyState: Readonly<Ref<ReadyState_2>>;
11081112
webSocketIns?: WebSocket;
11091113
}
11101114

packages/types/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vue-hooks-plus/types",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"description": "",
55
"files": [
66
"index.d.ts",

0 commit comments

Comments
 (0)