A
A
Alexey2017-06-13 10:30:29
typescript
Alexey, 2017-06-13 10:30:29

Private method in interface (typescript) is it possible?

Is it possible to create an interface with a private method:

interface I_Main {
    readonly RUNNING_SPEED: number;

    private getHeight():void;
}

In this case it produces an error: 'private modifier cannot appear on a type member' private getHeight():void;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Stroykin, 2017-06-13
@azovl

Interfaces define "Public" properties and methods and have no meaning from an access modifier like protected or privat
You can do something like:

interface IModuleMenuItem {
     getName(): string;
}

class ModuleMenuItem implements IModuleMenuItem {
    private name;

    public getName() {
        return name;    
    }

    protected setName(newName : string) {
        name = newName;
    }
}

Taken from here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question