Skip to content

Commit

Permalink
fix(useFavicon): writable return type (#2036)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
chaii3 and antfu committed Aug 4, 2022
1 parent 28c5a95 commit 06e2639
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions packages/core/useFavicon/index.ts
@@ -1,5 +1,6 @@
import type { MaybeComputedRef } from '@vueuse/shared'
import type { MaybeComputedRef, MaybeReadonlyRef, MaybeRef } from '@vueuse/shared'
import { isString, resolveRef } from '@vueuse/shared'
import type { ComputedRef, Ref, WritableComputedRef } from 'vue-demi'
import { watch } from 'vue-demi'
import type { ConfigurableDocument } from '../_configurable'
import { defaultDocument } from '../_configurable'
Expand All @@ -16,6 +17,14 @@ export interface UseFaviconOptions extends ConfigurableDocument {
* @param newIcon
* @param options
*/
export function useFavicon(
newIcon?: MaybeReadonlyRef<string | null | undefined>,
options?: UseFaviconOptions
): ComputedRef<string | null | undefined>
export function useFavicon(
newIcon: MaybeRef<string | null | undefined>,
options?: UseFaviconOptions
): Ref<string | null | undefined>
export function useFavicon(
newIcon: MaybeComputedRef<string | null | undefined> = null,
options: UseFaviconOptions = {},
Expand Down Expand Up @@ -43,7 +52,7 @@ export function useFavicon(
{ immediate: true },
)

return favicon
return favicon as WritableComputedRef<string | null | undefined>
}

export type UseFaviconReturn = ReturnType<typeof useFavicon>
13 changes: 11 additions & 2 deletions packages/shared/utils/types.ts
Expand Up @@ -31,10 +31,19 @@ export type MaybeRef<T> = T | Ref<T>
* Maybe it's a ref, or a plain value, or a getter function
*
* ```ts
* type MaybeComputedRef<T> = T | Ref<T> | (() => T)
* type MaybeComputedRef<T> = (() => T) | T | Ref<T> | ComputedRef<T>
* ```
*/
export type MaybeComputedRef<T> = (() => T) | T | Ref<T> | ComputedRef<T>
export type MaybeComputedRef<T> = MaybeReadonlyRef<T> | MaybeRef<T>

/**
* Maybe it's a computed ref, or a getter function
*
* ```ts
* type MaybeReadonlyRef<T> = (() => T) | ComputedRef<T>
* ```
*/
export type MaybeReadonlyRef<T> = (() => T) | ComputedRef<T>

/**
* Make all the nested attributes of an object or array to MaybeRef<T>
Expand Down

0 comments on commit 06e2639

Please sign in to comment.