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'