Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typedef): add return typedefs (#543) #544

Merged
merged 3 commits into from
May 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/createGlobalState/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export default defineComponent({
export declare function createGlobalState<T extends object>(
stateFactory: () => T
): () => T
export declare type CreateGlobalStateReturn = ReturnType<
typeof createGlobalState
>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/createGlobalState/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ export function createGlobalState<T extends object>(
return state
}
}

export type CreateGlobalStateReturn = ReturnType<typeof createGlobalState>
1 change: 1 addition & 0 deletions packages/core/useAsyncState/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export declare function useAsyncState<T>(
>
execute: (delay?: number) => Promise<void>
}
export declare type UseAsyncStateReturn = ReturnType<typeof useAsyncState>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useAsyncState/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ export function useAsyncState<T>(
execute,
}
}

export type UseAsyncStateReturn = ReturnType<typeof useAsyncState>
1 change: 1 addition & 0 deletions packages/core/useBattery/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export declare function useBattery({ navigator }?: ConfigurableNavigator): {
dischargingTime: Ref<number>
level: Ref<number>
}
export declare type UseBatteryReturn = ReturnType<typeof useBattery>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useBattery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ export function useBattery({ navigator = defaultNavigator }: ConfigurableNavigat
level,
}
}

export type UseBatteryReturn = ReturnType<typeof useBattery>
1 change: 1 addition & 0 deletions packages/core/useBreakpoints/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export declare function useBreakpoints<K extends string>(
isSmaller(k: K): boolean
isInBetween(a: K, b: K): boolean
}
export declare type UseBreakpointsReturn = ReturnType<typeof useBreakpoints>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useBreakpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ export function useBreakpoints<K extends string>(breakpoints: Breakpoints<K>, op
},
}
}

export type UseBreakpointsReturn = ReturnType<typeof useBreakpoints>
3 changes: 3 additions & 0 deletions packages/core/useBrowserLocation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export declare function useBrowserLocation({
protocol?: string | undefined
search?: string | undefined
}>
export declare type UseBrowserLocationReturn = ReturnType<
typeof useBrowserLocation
>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useBrowserLocation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ export function useBrowserLocation({ window = defaultWindow }: ConfigurableWindo

return state
}

export type UseBrowserLocationReturn = ReturnType<typeof useBrowserLocation>
1 change: 1 addition & 0 deletions packages/core/useDeviceMotion/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export declare function useDeviceMotion(options?: DeviceMotionOptions): {
rotationRate: Ref<DeviceMotionEventRotationRate | null>
interval: Ref<number>
}
export declare type UseDeviceMotionReturn = ReturnType<typeof useDeviceMotion>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useDeviceMotion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ export function useDeviceMotion(options: DeviceMotionOptions = {}) {
interval,
}
}

export type UseDeviceMotionReturn = ReturnType<typeof useDeviceMotion>
3 changes: 3 additions & 0 deletions packages/core/useDeviceOrientation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export declare function useDeviceOrientation(options?: ConfigurableWindow): {
beta: Ref<number | null>
gamma: Ref<number | null>
}
export declare type UseDeviceOrientationReturn = ReturnType<
typeof useDeviceOrientation
>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useDeviceOrientation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ export function useDeviceOrientation(options: ConfigurableWindow = {}) {
gamma,
}
}

export type UseDeviceOrientationReturn = ReturnType<typeof useDeviceOrientation>
3 changes: 3 additions & 0 deletions packages/core/useDevicePixelRatio/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export default {
export declare function useDevicePixelRatio({ window }?: ConfigurableWindow): {
pixelRatio: Ref<number>
}
export declare type UseDevicePixelRatioReturn = ReturnType<
typeof useDevicePixelRatio
>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useDevicePixelRatio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ export function useDevicePixelRatio({

return { pixelRatio }
}

export type UseDevicePixelRatioReturn = ReturnType<typeof useDevicePixelRatio>
3 changes: 3 additions & 0 deletions packages/core/useElementBounding/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export declare function useElementBounding(
width: Ref<number>
height: Ref<number>
}
export declare type UseElementBoundingReturn = ReturnType<
typeof useElementBounding
>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useElementBounding/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ export function useElementBounding(
height,
}
}

export type UseElementBoundingReturn = ReturnType<typeof useElementBounding>
1 change: 1 addition & 0 deletions packages/core/useElementSize/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export declare function useElementSize(
width: Ref<number>
height: Ref<number>
}
export declare type UseElementSizeReturn = ReturnType<typeof useElementSize>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useElementSize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ export function useElementSize(
height,
}
}

export type UseElementSizeReturn = ReturnType<typeof useElementSize>
1 change: 1 addition & 0 deletions packages/core/useEventSource/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export declare function useEventSource(
error: Ref<Event | null>
close: () => void
}
export declare type UseEventListenerReturn = ReturnType<typeof useEventListener>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useEventSource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ export function useEventSource(url: string, events: Array<string> = []) {
close,
}
}

export type UseEventListenerReturn = ReturnType<typeof useEventListener>
1 change: 1 addition & 0 deletions packages/core/useFullscreen/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export declare function useFullscreen(
exit: () => Promise<void>
toggle: () => Promise<void>
}
export declare type UseFullscreenReturn = ReturnType<typeof useFullscreen>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useFullscreen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,5 @@ export function useFullscreen(
toggle,
}
}

export type UseFullscreenReturn = ReturnType<typeof useFullscreen>
1 change: 1 addition & 0 deletions packages/core/useGeolocation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export declare function useGeolocation(options?: GeolocationOptions): {
readonly TIMEOUT: number
} | null>
}
export declare type UseGeolocationReturn = ReturnType<typeof useGeolocation>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useGeolocation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ export function useGeolocation(options: GeolocationOptions = {}) {
error,
}
}

export type UseGeolocationReturn = ReturnType<typeof useGeolocation>
9 changes: 5 additions & 4 deletions packages/core/useIdle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export interface IdleOptions
*/
initialState?: boolean
}
export interface UseIdleReturn {
idle: Ref<boolean>
lastActive: Ref<number>
}
/**
* Tracks whether the user is being inactive.
*
Expand All @@ -59,10 +63,7 @@ export interface IdleOptions
export declare function useIdle(
timeout?: number,
options?: IdleOptions
): {
idle: Ref<boolean>
lastActive: Ref<number>
}
): UseIdleReturn
```

## Source
Expand Down
9 changes: 7 additions & 2 deletions packages/core/useIdle/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ref } from 'vue-demi'
import { ConfigurableEventFilter, createFilterWrapper, throttleFilter, timestamp } from '@vueuse/shared'
import { Ref, ref } from 'vue-demi'
import { useEventListener, WindowEventName } from '../useEventListener'
import { ConfigurableWindow, defaultWindow } from '../_configurable'

Expand Down Expand Up @@ -27,6 +27,11 @@ export interface IdleOptions extends ConfigurableWindow, ConfigurableEventFilter
initialState?: boolean
}

export interface UseIdleReturn {
idle: Ref<boolean>
lastActive: Ref<number>
}

/**
* Tracks whether the user is being inactive.
*
Expand All @@ -37,7 +42,7 @@ export interface IdleOptions extends ConfigurableWindow, ConfigurableEventFilter
export function useIdle(
timeout: number = oneMinute,
options: IdleOptions = {},
) {
): UseIdleReturn {
const {
initialState = false,
listenForVisibilityChange = true,
Expand Down
3 changes: 3 additions & 0 deletions packages/core/useIntersectionObserver/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export declare function useIntersectionObserver(
isSupported: boolean | undefined
stop: () => void
}
export declare type UseIntersectionObserverReturn = ReturnType<
typeof useIntersectionObserver
>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useIntersectionObserver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ export function useIntersectionObserver(
stop,
}
}

export type UseIntersectionObserverReturn = ReturnType<typeof useIntersectionObserver>
1 change: 1 addition & 0 deletions packages/core/useMediaControls/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ export declare function useMediaControls(
isPictureInPicture: Ref<boolean>
onSourceError: EventHookOn<Event>
}
export declare type UseMediaControlsReturn = ReturnType<typeof useMediaControls>
export {}
```

Expand Down
2 changes: 2 additions & 0 deletions packages/core/useMediaControls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,5 @@ export function useMediaControls(target: MaybeRef<HTMLMediaElement | null | unde
onSourceError: sourceErrorEvent.on,
}
}

export type UseMediaControlsReturn = ReturnType<typeof useMediaControls>
1 change: 1 addition & 0 deletions packages/core/useMouse/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export declare function useMouse(options?: MouseOptions): {
y: Ref<number>
sourceType: Ref<MouseSourceType>
}
export declare type UseMouseReturn = ReturnType<typeof useMouse>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useMouse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ export function useMouse(options: MouseOptions = {}) {
sourceType,
}
}

export type UseMouseReturn = ReturnType<typeof useMouse>
3 changes: 3 additions & 0 deletions packages/core/useMouseInElement/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export declare function useMouseInElement(
isOutside: Ref<boolean>
stop: () => void
}
export declare type UseMouseInElementReturn = ReturnType<
typeof useMouseInElement
>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useMouseInElement/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ export function useMouseInElement(
stop,
}
}

export type UseMouseInElementReturn = ReturnType<typeof useMouseInElement>
1 change: 1 addition & 0 deletions packages/core/useMousePressed/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export declare function useMousePressed(options?: MousePressedOptions): {
pressed: Ref<boolean>
sourceType: Ref<MouseSourceType>
}
export declare type UseMousePressedReturn = ReturnType<typeof useMousePressed>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useMousePressed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ export function useMousePressed(options: MousePressedOptions = {}) {
sourceType,
}
}

export type UseMousePressedReturn = ReturnType<typeof useMousePressed>
3 changes: 3 additions & 0 deletions packages/core/useMutationObserver/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export declare function useMutationObserver(
isSupported: boolean | undefined
stop: () => void
}
export declare type UseMutationObserverReturn = ReturnType<
typeof useMutationObserver
>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useMutationObserver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ export function useMutationObserver(
stop,
}
}

export type UseMutationObserverReturn = ReturnType<typeof useMutationObserver>
1 change: 1 addition & 0 deletions packages/core/useNow/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export declare function useNow(options?: UseNowOptions<false>): Ref<Date>
export declare function useNow(options: UseNowOptions<true>): {
now: Ref<Date>
} & Pausable
export declare type UseNowReturn = ReturnType<typeof useNow>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useNow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ export function useNow(options: UseNowOptions<boolean> = {}) {
return now
}
}

export type UseNowReturn = ReturnType<typeof useNow>
3 changes: 3 additions & 0 deletions packages/core/useResizeObserver/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export declare function useResizeObserver(
isSupported: boolean | undefined
stop: () => void
}
export declare type UseResizeObserverReturn = ReturnType<
typeof useResizeObserver
>
export {}
```

Expand Down
2 changes: 2 additions & 0 deletions packages/core/useResizeObserver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@ export function useResizeObserver(
stop,
}
}

export type UseResizeObserverReturn = ReturnType<typeof useResizeObserver>
1 change: 1 addition & 0 deletions packages/core/useScriptTag/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export declare function useScriptTag(
load: (waitForScriptLoad?: boolean) => Promise<HTMLScriptElement | boolean>
unload: () => void
}
export declare type UseScriptTagReturn = ReturnType<typeof useScriptTag>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useScriptTag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,5 @@ export function useScriptTag(

return { scriptTag, load, unload }
}

export type UseScriptTagReturn = ReturnType<typeof useScriptTag>
1 change: 1 addition & 0 deletions packages/core/useShare/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export declare function useShare(
isSupported: boolean
share: (overrideOptions?: MaybeRef<ShareOptions>) => Promise<void>
}
export declare type UseShareReturn = ReturnType<typeof useShare>
```

## Source
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useShare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ export function useShare(shareOptions: MaybeRef<ShareOptions> = {}, options: Con
share,
}
}

export type UseShareReturn = ReturnType<typeof useShare>