TypeScript Tutorials #19 - Interface

Published: 15 June 2021
on channel: 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


On this page of the site you can watch the video online TypeScript Tutorials #19 - Interface with a duration of hours minute second in good quality, which was uploaded by the user Geeky Vro 15 June 2021, share the link with friends and acquaintances, this video has already been watched 12 times on youtube and it was liked by 1 viewers. Enjoy your viewing!