How to define a private property when implementing an interface in Typescript?

Posted by Jessica Taylor | Updated on

If you want to define a private property when implementing an interface in Typescript? Interfaces define “public” contracts and as such it doesn’t make sense to have protected or private access modifier on interfaces, which are more of a, let’s call it, implementation detail. As such you can’t do what you want with an interface.

If you are want to make the property read-only to consumers, but overridable in a subclass then you can do something like this:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers