如何在TypeScript中定义类的接口?
我必须指定接口中的所有操作,这些操作应该在类中实现 我从PHP转到了TypeScript 在PHP中创建接口非常简单:如何在TypeScript中定义类的接口?,typescript,typescript2.0,Typescript,Typescript2.0,我必须指定接口中的所有操作,这些操作应该在类中实现 我从PHP转到了TypeScript 在PHP中创建接口非常简单: interface iTemplate { public function move($name, $var); } 课程为: Class Mover inmpelments iTemplate { function move($name, $var){} } 如何在TypeScript中实现这一点?例如,我有一个类User,它可以: edit profi
interface iTemplate
{
public function move($name, $var);
}
课程为:
Class Mover inmpelments iTemplate {
function move($name, $var){}
}
如何在TypeScript中实现这一点?例如,我有一个类User,它可以:
edit profile
see users
etc
语法是相似的,但我建议你从一个教程或一本书或一个非常有用的。对于新语言编程中遇到的每一个语法细微差别,这都比问一个问题要好。我只找到了属性的接口:而不是函数的接口:
interface-Person{firstName:string;lastName:string;}
interface MyInterface {
editProfile(profileId: number): void;
seeUsers(): object[];
etc: string;
}
class MyImplementation implements MyInterface{
editProfile(profileId: number): void {
throw 'todo';
}
seeUsers(): object[] {
throw 'todo';
}
readonly etc = 'something else';
}