Typescript 我可以创建一个作为接口子集的接口吗?

Typescript 我可以创建一个作为接口子集的接口吗?,typescript,Typescript,给定 是否可以创建一个只包含标题:字符串但引用自foo{}的界面bar{}?例如,如果foo{}丢失title,则bar{}将出现编译器错误,直到title也从中删除 我能想到的唯一替代方法是先制作bar{},然后让foo{}扩展它您可以使用拾取: 类型栏=拾取 非常酷。是否可以对多个属性执行此操作?像type bar=Picktype bar=Pick interface foo { title: string; date: number; } type bar = Pick<

给定

是否可以创建一个只包含
标题:字符串
但引用自
foo{}
的界面
bar{}
?例如,如果
foo{}
丢失
title
,则
bar{}
将出现编译器错误,直到
title
也从中删除

我能想到的唯一替代方法是先制作
bar{}
,然后让
foo{}
扩展它

您可以使用
拾取

类型栏=拾取

非常酷。是否可以对多个属性执行此操作?像
type bar=Pick
type bar=Pick
interface foo {
  title: string;
  date: number;
}
type bar = Pick<foo, 'title'>