]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat(dx): throw an error if store id is missing (#2167)
authorskirtle <65301168+skirtles-code@users.noreply.github.com>
Mon, 24 Apr 2023 07:59:50 +0000 (08:59 +0100)
committerGitHub <noreply@github.com>
Mon, 24 Apr 2023 07:59:50 +0000 (09:59 +0200)
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
packages/pinia/__tests__/store.spec.ts
packages/pinia/src/store.ts

index 4e0a21ad7ea10419f1b6c89542813507b0019e9f..a9561cb0deed3fb2ee071a1a397e7e115af619a3 100644 (file)
@@ -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.'
+    )
+  })
 })
index 0c77d2e59c15ef54696c6e3de5c46ba3d6937762..37ce278d15ac856146102c3cfebac0fbe72db8b1 100644 (file)
@@ -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 {