我想从这样定义的接口(interface)获取“postType”属性
export interface PostType {
postType: {
title?: string;
content?: string;
};
}
我想取出并使用“postType”属性的目的如下
const fn = (post: Post) => {
...
}
我使用了“Pick”,但这不起作用。
export type Post = Pick<PostType, 'postType'>;
我配置上面接口(interface)的原因是PostType实际上是一个对应于另一个接口(interface)的属性。
所以我必须遵循PostType的界面。
我该怎么做?
最佳答案
如果我理解正确,你想这样做:PostType["postType"]
关于javascript - 如何从 typescript 获取接口(interface)的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60548398/