1
- import { TypeaheadProps , TypeaheadState } from '../types' ;
1
+ import { OptionType , TypeaheadProps , TypeaheadState } from '../types' ;
2
2
import { getOptionLabel } from '../utils' ;
3
3
4
- type Props = TypeaheadProps ;
4
+ type Props < Option extends OptionType > = TypeaheadProps < Option > ;
5
5
6
- export function getInitialState ( props : Props ) : TypeaheadState {
6
+ export function getInitialState < Option extends OptionType > ( props : Props < Option > ) : TypeaheadState < Option > {
7
7
const {
8
8
defaultInputValue,
9
9
defaultOpen,
@@ -40,7 +40,7 @@ export function getInitialState(props: Props): TypeaheadState {
40
40
} ;
41
41
}
42
42
43
- export function clearTypeahead ( state : TypeaheadState , props : Props ) {
43
+ export function clearTypeahead < Option extends OptionType > ( state : TypeaheadState < Option > , props : Props < Option > ) {
44
44
return {
45
45
...getInitialState ( props ) ,
46
46
isFocused : state . isFocused ,
@@ -49,15 +49,15 @@ export function clearTypeahead(state: TypeaheadState, props: Props) {
49
49
} ;
50
50
}
51
51
52
- export function clickOrFocusInput ( state : TypeaheadState ) {
52
+ export function clickOrFocusInput < Option extends OptionType > ( state : TypeaheadState < Option > ) {
53
53
return {
54
54
...state ,
55
55
isFocused : true ,
56
56
showMenu : true ,
57
57
} ;
58
58
}
59
59
60
- export function hideMenu ( state : TypeaheadState , props : Props ) {
60
+ export function hideMenu < Option extends OptionType > ( state : TypeaheadState < Option > , props : Props < Option > ) {
61
61
const { activeIndex, activeItem, initialItem, shownResults } =
62
62
getInitialState ( props ) ;
63
63
@@ -71,6 +71,6 @@ export function hideMenu(state: TypeaheadState, props: Props) {
71
71
} ;
72
72
}
73
73
74
- export function toggleMenu ( state : TypeaheadState , props : Props ) {
74
+ export function toggleMenu < Option extends OptionType > ( state : TypeaheadState < Option > , props : Props < Option > ) {
75
75
return state . showMenu ? hideMenu ( state , props ) : { ...state , showMenu : true } ;
76
76
}
0 commit comments