Typescript错误:在类型Class上定义为private的属性在Interface类型上定义为public

par*_*ent 6 typescript

我刚刚在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,我知道接口不能有访问修饰符!是什么赋予了?

打字稿操场示例

Wir*_*rie 6

您不能在类privategetUserInfo函数上拥有访问修饰符,Service因为它在接口上声明IService.

如果类是a IService,则需要公开声明接口的所有函数/属性.

module App.Services {

    export class Service implements App.Interfaces.IService {

        /* private <= remove */ getUserInfo(): void { }

    }   
}
Run Code Online (Sandbox Code Playgroud)