Skip to content

Commit b74eb4f

Browse files
skirtles-codeposva
andauthored
feat(dx): throw an error if store id is missing (#2167)
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
1 parent 27d490e commit b74eb4f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/pinia/__tests__/store.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,10 @@ describe('Store', () => {
379379
`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "anyName" in store "main".`
380380
).toHaveBeenWarnedTimes(1)
381381
})
382+
383+
it('throws an error if no store id is provided', () => {
384+
expect(() => defineStore({} as any)).toThrowError(
385+
'[🍍]: defineStore must be passed an id string, either as its first argument or via the "id" option.'
386+
)
387+
})
382388
})

packages/pinia/src/store.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,12 @@ export function defineStore(
879879
} else {
880880
options = idOrOptions
881881
id = idOrOptions.id
882+
883+
if (__DEV__ && typeof id !== 'string') {
884+
throw new Error(
885+
`[🍍]: "defineStore()" must be passed a store id as its first argument.`
886+
)
887+
}
882888
}
883889

884890
function useStore(pinia?: Pinia | null, hot?: StoreGeneric): StoreGeneric {

0 commit comments

Comments
 (0)