TypeScript Tutorials #19 - Interface

Publié le: 15 juin 2021
sur la chaîne: 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


Sur cette page du site, vous pouvez voir la vidéo en ligne TypeScript Tutorials #19 - Interface durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Geeky Vro 15 juin 2021, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 12 fois et il a aimé 1 téléspectateurs. Bon visionnage!