Skip to content

Commit

Permalink
feat(core): add invariant for getSources
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Dec 8, 2020
1 parent b57ccf3 commit 309371c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/autocomplete-core/src/utils/getNormalizedSources.ts
@@ -1,4 +1,4 @@
import { MaybePromise } from '@algolia/autocomplete-shared';
import { invariant, MaybePromise } from '@algolia/autocomplete-shared';

import {
AutocompleteSource,
Expand All @@ -16,6 +16,13 @@ export function getNormalizedSources<TItem extends BaseItem>(
options: GetSourcesParams<TItem>
): Promise<Array<InternalAutocompleteSource<TItem>>> {
return Promise.resolve(getSources(options)).then((sources) => {
invariant(
Array.isArray(sources),
`The \`getSources\` function must return an array of sources but returned type ${JSON.stringify(
typeof sources
)}:\n\n${JSON.stringify(sources, null, 2)}`
);

return Promise.all(
sources.filter(Boolean).map((source) => {
const normalizedSource: InternalAutocompleteSource<TItem> = {
Expand Down

0 comments on commit 309371c

Please sign in to comment.