From e8d1219886276258f4642fa1ec374f44b08578b8 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sun, 4 Feb 2024 22:11:53 +0000 Subject: [PATCH] fix(nuxt): remove key from `useId` type signature (#25614) --- packages/nuxt/src/app/composables/id.ts | 1 + test/fixtures/basic-types/types.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/packages/nuxt/src/app/composables/id.ts b/packages/nuxt/src/app/composables/id.ts index 42db3eb2a1..5b0c666cb9 100644 --- a/packages/nuxt/src/app/composables/id.ts +++ b/packages/nuxt/src/app/composables/id.ts @@ -7,6 +7,7 @@ const ATTR_KEY = 'data-n-ids' /** * Generate an SSR-friendly unique identifier that can be passed to accessibility attributes. */ +export function useId (): string export function useId (key?: string): string { if (typeof key !== 'string') { throw new TypeError('[nuxt] [useId] key must be a string.') diff --git a/test/fixtures/basic-types/types.ts b/test/fixtures/basic-types/types.ts index a2617138ec..429a5d27d6 100644 --- a/test/fixtures/basic-types/types.ts +++ b/test/fixtures/basic-types/types.ts @@ -362,6 +362,11 @@ describe('composables', () => { expectTypeOf(useFetch('/test', { default: () => 500 }).data).toEqualTypeOf>() }) + it('prevents passing string to `useId`', () => { + // @ts-expect-error providing a key is not allowed + useId('test') + }) + it('enforces readonly cookies', () => { // @ts-expect-error readonly cookie useCookie('test', { readonly: true }).value = 'thing'