TypeScript Tutorials #19 - Interface

Опубликовано: 15 Июнь 2021
на канале: Geeky Vro
12
1

#Interface

One of TypeScript’s core principles is that type checking focuses on the shape that values have. This is sometimes called “duck typing” or “structural subtyping”. In TypeScript, interfaces fill the role of naming these types, and are a powerful way of defining contracts within your code as well as contracts with code outside of your project.

Not all properties of an interface may be required. Some exist under certain conditions or may not be there at all. These optional properties are popular when creating patterns like “option bags” where you pass an object to a function that only has a couple of properties filled in.

Interfaces with optional properties are written similar to other interfaces, with each optional property denoted by a ? at the end of the property name in the declaration. The advantage of optional properties is that you can describe these possibly available properties while still also preventing the use of properties that are not part of the interface.

Some properties should only be modifiable when an object is first created. You can specify this by putting "readonly" before the name of the property:

interface Point {
readonly x: number;
readonly y: number;
}

🔔 Subscribe for more free YouTube video:    / @geekyvro2637  

✅ Let's connect:

Twitter - @AnshulLaddha3

Instagram - /anshul_laddha


На этой странице сайта вы можете посмотреть видео онлайн TypeScript Tutorials #19 - Interface длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Geeky Vro 15 Июнь 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 12 раз и оно понравилось 1 зрителям. Приятного просмотра!