我有一个store ,我想在其中适当地管理ID.假设我有以下帖子store :
type Post = {
id: number;
title: string;
body?: string;
}
type Store = {
postId: number | null;
posts: Post[];
addPost: (post: Omit<Post, "id">) => Promise<void>;
updatePost: (id: number, post: Partial<Post>) => Promise<void>;
};
如果 Select 了帖子,则将postID设置为选定的帖子ID.我想告诉TypeScrip,这个postID总是/应该总是出现在帖子中.因此,我可以肯定,如果我想找到合适的职位,它总是在那里.
在打印脚本中有什么方法可以做到这一点吗?
大概是这样的:
type Store = {
postId: (number in StoreType.posts.key<"id">) | null;
posts: Post[];
// ...
};