如何在 TypeScript 中为 class 定义接口?
How to define interface for class in TypeScript?
我必须在 class 中指定接口中的所有操作。
我从 PHP 转移到 TypeScript。
在 PHP 中创建接口非常简单:
interface iTemplate
{
public function move($name, $var);
}
Class 是:
Class Mover inmpelments iTemplate {
function move($name, $var){}
}
如何在 TypeScript 中做到这一点?例如,我有 class 用户,可以:
edit profile
see users
etc
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';
}
我必须在 class 中指定接口中的所有操作。
我从 PHP 转移到 TypeScript。
在 PHP 中创建接口非常简单:
interface iTemplate
{
public function move($name, $var);
}
Class 是:
Class Mover inmpelments iTemplate {
function move($name, $var){}
}
如何在 TypeScript 中做到这一点?例如,我有 class 用户,可以:
edit profile
see users
etc
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';
}