TypeScript Tutorials #19 - Interface

Veröffentlicht am: 15 Juni 2021
auf dem Kanal: 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


Auf dieser Seite können Sie das Online-Video TypeScript Tutorials #19 - Interface mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Geeky Vro 15 Juni 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 12 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!