TypeScript类的接口
类与接口
// 接口
interface interHuman {
speak():any;
}
// 类
class Human implements interHuman {
speak() {
console.log('我可以说话')
}
}
这是最简单的用法,接口interHuman对Human类的约束。
一个类可以使用两个或者多个接口进行约束。
// 接口 1
interface interHuman {
speak():any;
}
// 接口2
interface inter2 {
walk():any;
}
// 类
class Human implements interHuman, implements inter2 {
speak() {
console.log('我可以说话')
}
}
接口与接口之间可以实现继承。extends。
// 父接口
interface interFather {
father():any;
}
// 子接口
interface interSon extends interFather {
son():any;
}
// 类
class Huamn implements interSon {
son() {
console.log('我是一个儿子')
}
father() {
console.log('我是父亲')
}
}
const d = new Huamn()
d.son()
文章为作者独立观点,不代表 股票程序化软件自动交易接口观点