Languages
[Edit]
EN

TypeScript - interface getter

17 points
Created by:
Richard-Bevan
413

In this article, we would like to show how in TypeScript create getter in interface and later implement it.

W TypeScript nie jest możliwe dodawanie getterów bezpośrednio do interfejsu. W interfejsie można określić tylko właściwość tylko do odczytu.

Quick solution:

 

Practical example

Edit

Complilation and running:

Output:

Run it online here.

 

Notes:

  • to enable getters support --targer ES5 parameter during complilation is necessary (check full list of targets here)
  • readonly keyword in interface is optional

 

References

Edit
  1. Readonly properties - Microsoft Docs
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

TypeScript

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join