我在这个应用程序中有多个函数返回promises,并且都用Flow类型注释。然而,有2个给我流动错误(它们确实有效),我似乎无法破译。任何见解将不胜感激!
功能1
拨打
const posts = await getPostRoutes({ brand, reusables, acf, wp })
声明
export async function getPostRoutes (
{ brand, reusables, acf, wp } :
{ brand: PropsBrand, reusables: Object, acf: string, wp: string },
) : Promise<Array<{
path: string,
component: string,
getProps: Function,
}>> {
const { data: posts_index } = await axios.get(`${acf}/options/posts_index`)
const { data: posts } = await axios.get(`${wp}/posts?_embed`)
return [{
path: `${posts_index.acf.posts_index_blog_slug}`,
component: 'src/containers/Posts',
getProps: () => ({
brand,
title: posts_index.acf.posts_index_blog_title,
subtitle: posts_index.acf.posts_index_blog_subtitle,
reusables: {
contact_columns: reusables['3_columns_contact_block_contact_columns'],
},
}),
children: posts.map(post => ({
path: `/${post.slug}`,
component: 'src/containers/Posts/Post',
getProps: () => ({
...cleanWPJson(post),
brand,
reusables: {
ball_rolling_cta: {
image: reusables.ball_rolling_cta_background_image,
label: reusables.ball_rolling_cta_label,
link: reusables.ball_rolling_cta_link,
},
},
}),
})),
}]
}
流量错误
[flow] Promise (This type is incompatible with the expected param type of union: type application of class `Promise` | type parameter `T` of await Member 1: type application of class `Promise` Error: type application of async return This type is incompatible with the expected return type of type application of identifier `Promise` Member 2: type parameter `T` of await Error: Promise This type is incompatible with $Iterable)
功能2
拨打
const recentPortfolioPieces = await getRecentPortfolioPieces({ wp, count: 3 })
声明
export async function getRecentPortfolioPieces (
{ wp, count } : { wp: string, count: number},
) : Promise<Array<{
title: string,
id: number,
categories: Array<Object>,
slug: string,
thumbnail: {
alt: string,
url: string,
},
}>> {
const { data: recentPortfolioPieces } = await axios.get(`${wp}/portfolio?per_page=${count}`)
return recentPortfolioPieces.map(piece => {
return {
title: piece.title.rendered,
id: piece.id,
categories: piece.pure_taxonomies.portfolio_cat,
slug: '',
thumbnail: {
alt: '',
url: '',
},
}
})
}
流量错误
[flow] Promise (This type is incompatible with the expected param type of union: type application of class `Promise` | type parameter `T` of await Member 1: type application of class `Promise` Error: object literal This type is incompatible with the expected param type of object type Member 2: type parameter `T` of await Error: object literal This type is incompatible with the expected param type of object type)
我确信这与Flow如何理解我在这里缺少的承诺有关。再次,任何见解或帮助将不胜感激。