Typescript error: a property that is defined as private in the Class type is defined as public in the Interface type

I just started a new project in TypeScript 0.9.5, and the following code throws an error:

The Service class is declared by IService, but does not implement it. The 'getUserInfo' property, defined as private in the Service type, is defined as public in the IService type

 module App.Interfaces {

     export interface IService {
        getUserInfo(): void;

    }   
}

module App.Services {

    export class Service implements App.Interfaces.IService {

        private getUserInfo(): void { }

    }   
}

As long as I used TypeScript, I know that interfaces cannot have access modifiers! What gives?

Typescript example playground

+4
source share
1 answer

You cannot have an access modifier privatein a function getUserInfoin a class Serviceas it is declared on an interface IService.

IService, / , .

module App.Services {

    export class Service implements App.Interfaces.IService {

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

    }   
}
+6

Source: https://habr.com/ru/post/1523732/


All Articles