Consider the following code ( also on TS Play )
interface Props<Item> {
selectedItem?: Item
}
function makeReturn(props: Props) { // complaints : Generic type 'Props<Item>' requires 1 type argument(s).
if (props.selectedItem) {
return props.selectedItem
}
return ''
}
function useAutosuggest<Item>(
userProps: Props<Item> = {}
) {
const retVal = makeReturn(userProps);
return retVal;
}
interface MyItem {
city: 'string',
rating: number
}
const selectedItem = useAutosuggest<MyItem>()
My thought process is – what do I do, so that the makeReturn function be able to know that selectedItem should be of whatever type useAutosuggest takes in (in this case MyType). I'm not sure if I'm thinking correctly. If I am, what to do to act upon this thought process, if not what am I thinking wrong?