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

fix(useFavicon): writable return type #2036

Merged
merged 3 commits into from Aug 4, 2022
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
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