Reputation: 20172
How would I Type this incoming function prop for this React Hook Componet? Right now I just put any
which is bad but I don't know how to type it, I'm new to TS:
const FeaturedCompanies = (findFeaturedCompanies: any) => {
...
}
It's just a plain function:
async function findFeaturedCompanies(): Promise<Array<Company>> {
const response = await fetchFeaturedCompanies(),
...
}
Upvotes: 0
Views: 69
Reputation: 370679
Since findFeaturedCompanies
returns Promise<Array<Company>>
, just type the function as one which returns that:
const FeaturedCompanies = (
findFeaturedCompanies: () => Promise<Array<Company>>
) => {
If findFeaturedCompanies
happens to be in scope of the FeaturedCompanies
declaration, you could also do
const FeaturedCompanies = (
findFeaturedCompanies: typeof findFeaturedCompanies
) => {
Upvotes: 2