fix(nuxt): allow cookies to be set to null to unset them (#8769)

Co-authored-by: Magyar Balázs <magyarb94@gmail.com>
This commit is contained in:
Daniel Roe 2022-11-09 09:59:23 +01:00 committed by GitHub
parent 1582f8ec01
commit e76ebdddd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -15,7 +15,7 @@ export interface CookieOptions<T = any> extends _CookieOptions {
default?: () => T | Ref<T>
}
export interface CookieRef<T> extends Ref<T> {}
export interface CookieRef<T> extends Ref<T | null> {}
const CookieDefaults: CookieOptions<any> = {
path: '/',

View File

@ -154,8 +154,9 @@ describe('composables', () => {
expectTypeOf(useState('test', () => ref('hello'))).toEqualTypeOf<Ref<string>>()
expectTypeOf(useState('test', () => 'hello')).toEqualTypeOf<Ref<string>>()
expectTypeOf(useCookie('test', { default: () => ref(500) })).toEqualTypeOf<Ref<number>>()
expectTypeOf(useCookie('test', { default: () => 500 })).toEqualTypeOf<Ref<number>>()
expectTypeOf(useCookie('test', { default: () => ref(500) })).toEqualTypeOf<Ref<number | null>>()
expectTypeOf(useCookie('test', { default: () => 500 })).toEqualTypeOf<Ref<number | null>>()
useCookie('test').value = null
expectTypeOf(useAsyncData('test', () => Promise.resolve(500), { default: () => ref(500) }).data).toEqualTypeOf<Ref<number | null>>()
expectTypeOf(useAsyncData('test', () => Promise.resolve(500), { default: () => 500 }).data).toEqualTypeOf<Ref<number | null>>()