From f5a825e34cc46055e073961cc3830c7ca4e3b8a4 Mon Sep 17 00:00:00 2001 From: Nikita Mikhailov Date: Wed, 3 Aug 2022 19:44:40 +0300 Subject: [PATCH 1/2] fix(useFavicon): writable return type --- packages/core/useFavicon/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/core/useFavicon/index.ts b/packages/core/useFavicon/index.ts index e4aa4f53529..6e9993ef1cc 100644 --- a/packages/core/useFavicon/index.ts +++ b/packages/core/useFavicon/index.ts @@ -1,5 +1,6 @@ -import type { MaybeComputedRef } from '@vueuse/shared' +import type { 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' @@ -9,6 +10,9 @@ export interface UseFaviconOptions extends ConfigurableDocument { rel?: string } +export type UseFaviconValue = string | null | undefined +export type UseFaviconGetter = () => UseFaviconValue + /** * Reactive favicon. * @@ -16,8 +20,11 @@ export interface UseFaviconOptions extends ConfigurableDocument { * @param newIcon * @param options */ +export function useFavicon(newIcon: ComputedRef | UseFaviconGetter, options?: UseFaviconOptions): ComputedRef +export function useFavicon(newIcon: MaybeRef, options?: UseFaviconOptions): Ref +export function useFavicon(newIcon?: ComputedRef | MaybeRef | UseFaviconGetter, options?: UseFaviconOptions): Ref export function useFavicon( - newIcon: MaybeComputedRef = null, + newIcon: ComputedRef | MaybeRef | UseFaviconGetter = null, options: UseFaviconOptions = {}, ) { const { @@ -43,7 +50,6 @@ export function useFavicon( { immediate: true }, ) - return favicon + return favicon as WritableComputedRef } - export type UseFaviconReturn = ReturnType From 8a95d1c40f0037ebf2263a8dbe071c13680a1633 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 4 Aug 2022 11:58:51 +0800 Subject: [PATCH 2/2] chore: update --- packages/core/useFavicon/index.ts | 19 +++++++++++-------- packages/shared/utils/types.ts | 13 +++++++++++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/core/useFavicon/index.ts b/packages/core/useFavicon/index.ts index 6e9993ef1cc..42b8b77ee4a 100644 --- a/packages/core/useFavicon/index.ts +++ b/packages/core/useFavicon/index.ts @@ -1,4 +1,4 @@ -import type { MaybeRef } 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' @@ -10,9 +10,6 @@ export interface UseFaviconOptions extends ConfigurableDocument { rel?: string } -export type UseFaviconValue = string | null | undefined -export type UseFaviconGetter = () => UseFaviconValue - /** * Reactive favicon. * @@ -20,11 +17,16 @@ export type UseFaviconGetter = () => UseFaviconValue * @param newIcon * @param options */ -export function useFavicon(newIcon: ComputedRef | UseFaviconGetter, options?: UseFaviconOptions): ComputedRef -export function useFavicon(newIcon: MaybeRef, options?: UseFaviconOptions): Ref -export function useFavicon(newIcon?: ComputedRef | MaybeRef | UseFaviconGetter, options?: UseFaviconOptions): Ref export function useFavicon( - newIcon: ComputedRef | MaybeRef | UseFaviconGetter = null, + newIcon?: MaybeReadonlyRef, + options?: UseFaviconOptions +): ComputedRef +export function useFavicon( + newIcon: MaybeRef, + options?: UseFaviconOptions +): Ref +export function useFavicon( + newIcon: MaybeComputedRef = null, options: UseFaviconOptions = {}, ) { const { @@ -52,4 +54,5 @@ export function useFavicon( return favicon as WritableComputedRef } + export type UseFaviconReturn = ReturnType diff --git a/packages/shared/utils/types.ts b/packages/shared/utils/types.ts index d0189383931..ddac273e445 100644 --- a/packages/shared/utils/types.ts +++ b/packages/shared/utils/types.ts @@ -31,10 +31,19 @@ export type MaybeRef = T | Ref * Maybe it's a ref, or a plain value, or a getter function * * ```ts - * type MaybeComputedRef = T | Ref | (() => T) + * type MaybeComputedRef = (() => T) | T | Ref | ComputedRef * ``` */ -export type MaybeComputedRef = (() => T) | T | Ref | ComputedRef +export type MaybeComputedRef = MaybeReadonlyRef | MaybeRef + +/** + * Maybe it's a computed ref, or a getter function + * + * ```ts + * type MaybeReadonlyRef = (() => T) | ComputedRef + * ``` + */ +export type MaybeReadonlyRef = (() => T) | ComputedRef /** * Make all the nested attributes of an object or array to MaybeRef