这很有效
interface test{
imp():number;
}
Run Code Online (Sandbox Code Playgroud)
但是可以在里面实现一个功能.
interface test{
imp():number{
// do something if it is not overwritten
}
}
Run Code Online (Sandbox Code Playgroud)
这对我来说不适用于打字稿,但可能有一些保留字,例如默认或类似,用于在接口内实现一个函数,如果默认工作,则不会被覆盖.
bas*_*rat 13
不是.TypeScript接口在运行时不可用,也就是说它们在生成的JavaScript中完全不存在.
也许你打算用class
:
class Test{
imp(){return 123}
}
Run Code Online (Sandbox Code Playgroud)
抽象类将满足您的需求
abstract class Department {
constructor(public name: string) {
}
printName(): void {
console.log("Department name: " + this.name);
}
abstract printMeeting(): void; // must be implemented in derived classes
}
class AccountingDepartment extends Department {
constructor() {
super("Accounting and Auditing"); // constructors in derived classes must call super()
}
printMeeting(): void {
console.log("The Accounting Department meets each Monday at 10am.");
}
generateReports(): void {
console.log("Generating accounting reports...");
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9124 次 |
最近记录: |