From: skirtle <65301168+skirtles-code@users.noreply.github.com> Date: Mon, 24 Apr 2023 07:59:50 +0000 (+0100) Subject: feat(dx): throw an error if store id is missing (#2167) X-Git-Tag: @pinia/nuxt@0.4.10~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b74eb4f9b5a2a20a9c8d3cedd221eea8dde201f6;p=thirdparty%2Fvuejs%2Fpinia.git feat(dx): throw an error if store id is missing (#2167) Co-authored-by: Eduardo San Martin Morote --- diff --git a/packages/pinia/__tests__/store.spec.ts b/packages/pinia/__tests__/store.spec.ts index 4e0a21ad..a9561cb0 100644 --- a/packages/pinia/__tests__/store.spec.ts +++ b/packages/pinia/__tests__/store.spec.ts @@ -379,4 +379,10 @@ describe('Store', () => { `[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "anyName" in store "main".` ).toHaveBeenWarnedTimes(1) }) + + it('throws an error if no store id is provided', () => { + expect(() => defineStore({} as any)).toThrowError( + '[🍍]: defineStore must be passed an id string, either as its first argument or via the "id" option.' + ) + }) }) diff --git a/packages/pinia/src/store.ts b/packages/pinia/src/store.ts index 0c77d2e5..37ce278d 100644 --- a/packages/pinia/src/store.ts +++ b/packages/pinia/src/store.ts @@ -879,6 +879,12 @@ export function defineStore( } else { options = idOrOptions id = idOrOptions.id + + if (__DEV__ && typeof id !== 'string') { + throw new Error( + `[🍍]: "defineStore()" must be passed a store id as its first argument.` + ) + } } function useStore(pinia?: Pinia | null, hot?: StoreGeneric): StoreGeneric {