Skip to content

Commit

Permalink
type: fix type
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonYong committed Jul 7, 2024
1 parent a08b5c4 commit bd880c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/hooks/src/useRequest/plugins/useThrottlePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed, unref, watchEffect } from 'vue'
import { DebouncedFunc, ThrottleSettings } from 'lodash'
import { DebouncedFuncLeading, ThrottleSettings } from 'lodash'
import throttle from 'lodash/throttle'
import { UseRequestPlugin } from '../types'

Expand All @@ -18,7 +18,7 @@ const useThrottlePlugin: UseRequestPlugin<unknown, unknown[]> = (
return ret
})

const throttledRef = computed<DebouncedFunc<any>>(() =>
const throttledRef = computed<DebouncedFuncLeading<(callback: () => void) => void>>(() =>
throttle(
(callback: () => void) => {
callback()
Expand Down Expand Up @@ -52,7 +52,7 @@ const useThrottlePlugin: UseRequestPlugin<unknown, unknown[]> = (
}

return {
name: "throttlePlugin",
name: 'throttlePlugin',
onCancel: () => {
throttledRef.value?.cancel()
},
Expand Down
18 changes: 10 additions & 8 deletions packages/hooks/src/useSet/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref, Ref, markRaw, readonly } from 'vue'
import { ref, Ref, markRaw, readonly, UnwrapRef } from 'vue'

interface UseSetActions<T> {
add: (value: T) => void
Expand All @@ -8,36 +8,38 @@ interface UseSetActions<T> {
reset: () => void
}

function useSet<T = any>(initialValue?: T[]): [Readonly<Ref<Set<T>>>, UseSetActions<T>]
function useSet<T = any>(
initialValue?: UnwrapRef<T>[],
): [Readonly<Ref<Set<UnwrapRef<T>>>>, UseSetActions<UnwrapRef<T>>]

function useSet<T = any>(initialValue?: T[]) {
function useSet<T = any>(initialValue?: UnwrapRef<T>[]) {
const getInitValue = () => {
return initialValue === undefined ? new Set<T>() : new Set(initialValue)
return initialValue === undefined ? new Set<UnwrapRef<T>>() : new Set(initialValue)
}
const state = ref(getInitValue())

const actions: UseSetActions<T> = {
const actions: UseSetActions<UnwrapRef<T>> = {
/**
* Add item
* @param value T
*/
add: (value: T) => {
add: value => {
state.value.add(value)
},

/**
* Remove item
* @param value T
*/
remove: (value: T) => {
remove: value => {
state.value.delete(value)
},

/**
* Set has
* @param value T
*/
has: (value: T) => state.value.has(value),
has: value => state.value.has(value),

/**
* Clear Set
Expand Down

0 comments on commit bd880c3

Please sign in to comment.