Skip to content

Commit

Permalink
fix(js): fix type for getSources
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Sep 8, 2020
1 parent 18e88ae commit 4a29700
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
45 changes: 35 additions & 10 deletions packages/autocomplete-js/src/__tests__/autocomplete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ describe('autocomplete-js', () => {
{ label: 'Item 3' },
];
},
templates: {
item({ item }) {
return item.label;
},
},
},
];
},
Expand All @@ -29,7 +34,6 @@ describe('autocomplete-js', () => {
aria-expanded="false"
aria-haspopup="listbox"
aria-labelledby="autocomplete-label"
aria-owns="undefined"
class="aa-Autocomplete"
role="combobox"
>
Expand All @@ -39,20 +43,35 @@ describe('autocomplete-js', () => {
novalidate=""
role="search"
>
<label
class="aa-Label"
for="autocomplete-input"
id="autocomplete-label"
>
Search items
</label>
<div
class="aa-InputWrapper"
>
<label
class="aa-Label"
for="autocomplete-input"
id="autocomplete-label"
>
<svg
height="20"
viewBox="0 0 20 20"
width="20"
>
<path
d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z"
fill="none"
fillrule="evenodd"
stroke="currentColor"
strokelinecap="round"
strokelinejoin="round"
/>
</svg>
</label>
<input
aria-activedescendant="undefined"
aria-autocomplete="list"
aria-controls="undefined"
aria-labelledby="autocomplete-label"
autocapitalize="off"
autocomplete="off"
Expand All @@ -75,6 +94,7 @@ describe('autocomplete-js', () => {
<div
class="aa-Dropdown"
hidden=""
style="top: 0px; left: 0px; right: 0px; max-width: unset;"
/>
</div>
</div>
Expand All @@ -97,6 +117,11 @@ describe('autocomplete-js', () => {
{ label: 'Item 3' },
];
},
templates: {
item({ item }) {
return item.label;
},
},
},
];
},
Expand Down
8 changes: 5 additions & 3 deletions packages/autocomplete-js/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import {
AutocompleteSetters as AutocompleteCoreSetters,
PublicAutocompleteOptions as PublicAutocompleteCoreOptions,
AutocompleteState as AutocompleteCoreState,
AutocompleteSource as AutocompleteCoreSource,
PublicAutocompleteSource as PublicAutocompleteCoreSource,
GetSourcesParams,
} from '@algolia/autocomplete-core';

type Template<TParams> = (params: TParams) => string | void;

export type AutocompleteSource<TItem> = AutocompleteCoreSource<TItem> & {
export type AutocompleteSource<TItem> = PublicAutocompleteCoreSource<TItem> & {
/**
* Templates to display in the autocomplete dropdown.
*
Expand Down Expand Up @@ -42,7 +42,9 @@ export type AutocompleteSource<TItem> = AutocompleteCoreSource<TItem> & {

type GetSources<TItem> = (
params: GetSourcesParams<TItem>
) => Promise<Array<AutocompleteSource<TItem>>>;
) =>
| Array<AutocompleteSource<TItem>>
| Promise<Array<AutocompleteSource<TItem>>>;

export interface AutocompleteOptions<TItem>
extends PublicAutocompleteCoreOptions<TItem> {
Expand Down

0 comments on commit 4a29700

Please sign in to comment.