更改文件以使用打字稿。学习打字稿。
我将签名更改为
export default function PostForm( post: PostInterface, username: string, posts: PostInterface[], setPosts: PostInterface[], setPostMessage:string ) {
...
const newPost = { title, content, author: username, slug, created };
setPosts([newPost, ...posts])
但是现在我遇到setPosts
的错误:
TypeScript error: This expression is not callable.
Type 'PostInterface[]' has no call signatures. TS2349
vScode说this expression is not callable
。
setPosts
的类型为PostInterface[]
,换句话说,setPosts应该是PostInterface
的数组。您可能希望setPosts
的类型是某种函数。例如:
setPosts: (newPosts: PostInterface[]) => PostInterface[]
// OR, if setPosts doesn't return anything
setPosts: (newPosts: PostInterface[]) => void