Skip to content

Commit 36d7e58

Browse files
committed
fix: throw when setup closure does not return a Ditto instance
1 parent 78a7509 commit 36d7e58

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/DittoProvider.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,25 @@ export const DittoProvider: React.FunctionComponent<DittoProviderProps> = (
7070
const dittoHash: DittoHash = {}
7171
const dittos: Ditto[] = setupReturnValue
7272
for (const ditto of dittos) {
73+
if (!(ditto instanceof Ditto)) {
74+
throw new Error(
75+
// Type is `never` because correct use never reaches this point
76+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
77+
`expected an array of Ditto instances to be returned by the setup function, but at least one element is not a Ditto instance (got ${ditto})`,
78+
)
79+
}
7380
dittoHash[ditto.persistenceDirectory] = ditto
7481
}
7582
setDittoHash(dittoHash)
7683
} else {
7784
const ditto = setupReturnValue
85+
if (!(ditto instanceof Ditto)) {
86+
throw new Error(
87+
// Type is `never` because correct use never reaches this point
88+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
89+
`expected a Ditto instance to be returned by the setup function, but got ${ditto}`,
90+
)
91+
}
7892
const dittoHash: DittoHash = {}
7993
dittoHash[ditto.persistenceDirectory] = ditto
8094
setDittoHash(dittoHash)

0 commit comments

Comments
 (0)