From c26979a047a07ab006e62828934a4cd4dc5dd91b Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 2 Dec 2022 09:45:33 +0000 Subject: [PATCH] fix(nuxt): `useCookie` with defaults should return non-null value (#9449) --- packages/nuxt/src/app/composables/cookie.ts | 4 ++-- test/fixtures/basic/types.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/nuxt/src/app/composables/cookie.ts b/packages/nuxt/src/app/composables/cookie.ts index 7a7d6eb937..666e43961f 100644 --- a/packages/nuxt/src/app/composables/cookie.ts +++ b/packages/nuxt/src/app/composables/cookie.ts @@ -15,7 +15,7 @@ export interface CookieOptions extends _CookieOptions { default?: () => T | Ref } -export interface CookieRef extends Ref {} +export interface CookieRef extends Ref {} const CookieDefaults: CookieOptions = { path: '/', @@ -23,7 +23,7 @@ const CookieDefaults: CookieOptions = { encode: val => encodeURIComponent(typeof val === 'string' ? val : JSON.stringify(val)) } -export function useCookie (name: string, _opts?: CookieOptions): CookieRef { +export function useCookie (name: string, _opts?: CookieOptions): CookieRef { const opts = { ...CookieDefaults, ..._opts } const cookies = readRawCookies(opts) || {} diff --git a/test/fixtures/basic/types.ts b/test/fixtures/basic/types.ts index db32fda10d..0dab812239 100644 --- a/test/fixtures/basic/types.ts +++ b/test/fixtures/basic/types.ts @@ -161,9 +161,9 @@ describe('composables', () => { expectTypeOf(useState('test', () => ref('hello'))).toEqualTypeOf>() expectTypeOf(useState('test', () => 'hello')).toEqualTypeOf>() - expectTypeOf(useCookie('test', { default: () => ref(500) })).toEqualTypeOf>() - expectTypeOf(useCookie('test', { default: () => 500 })).toEqualTypeOf>() - useCookie('test').value = null + expectTypeOf(useCookie('test', { default: () => ref(500) })).toEqualTypeOf>() + expectTypeOf(useCookie('test', { default: () => 500 })).toEqualTypeOf>() + useCookie('test').value = null expectTypeOf(useAsyncData('test', () => Promise.resolve(500), { default: () => ref(500) }).data).toEqualTypeOf>() expectTypeOf(useAsyncData('test', () => Promise.resolve(500), { default: () => 500 }).data).toEqualTypeOf>()