我刚刚在TypeScript 0.9.5中启动了一个新项目,以下代码抛出错误:
类服务声明了IService但没有实现它.定义为私有类型Service的属性'getUserInfo'在类型IService上定义为public
module App.Interfaces {
export interface IService {
getUserInfo(): void;
}
}
module App.Services {
export class Service implements App.Interfaces.IService {
private getUserInfo(): void { }
}
}
Run Code Online (Sandbox Code Playgroud)
只要我使用TypeScript,我知道接口不能有访问修饰符!是什么赋予了?
您不能在类private
的getUserInfo
函数上拥有访问修饰符,Service
因为它在接口上声明IService
.
如果类是a IService
,则需要公开声明接口的所有函数/属性.
module App.Services {
export class Service implements App.Interfaces.IService {
/* private <= remove */ getUserInfo(): void { }
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5893 次 |
最近记录: |