我正在学习打字,我想用interface
,I've found a blog post来扩展type
,这意味着type
不可能扩展/实现interfaces
.
以下是我想要做的代码示例:
interface IPet {
needsFood: boolean
}
// How I would like to use the IPet interface with a type,
type Cat implements IPet = {
needsFood: boolean,
color: string,
}
上述代码示例给出了一个错误.'IPet' only refers to a type, but is being used as a value here.
个
下面是我如何使用Class
的iPet界面,但type
有可能具有相同的行为吗
class Cat implements IPet {
needsFood: boolean;
color: string
}
有没有办法让type
实现一个接口?或者,如果我想使用接口,我需要使用Class
吗?
Edit:感谢所有的 comments ,我已经更新了一个代码示例的问题.我在这里真正寻找的基本上只是一个是/否的答案,是否有可能让一个类型扩展/实现一个接口.