Interface vs Class | TypeScript Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi this is annapurna in this new chapter  we will see how we can create our own   custom types in typescript and take full  advantage of the create type checking support   of typescript we will see the object oriented side  of typescript creating custom types in typescript   is mostly about using interfaces and classes  we will first check out the difference between   the two this will help us to choose whether we  need an interface or we need a class when we   create the classes we will have multiple  typescript source files so along the way   we will also see how to configure a typescript  project to support multiple typescript files   let us start with having a look at the difference  between the two we use both interface and class to   create custom types in typescript however there  are significant differences between the two   interfaces and classes both have properties  properties includes the fields and the methods   however for interface we just define the  signature of the property meaning the   property just has a name and the type annotation  for the methods they are just the method signature   whereas for classes the properties have  signatures as well as they are implemented   we can use the getter and setter methods for  the properties in the class the methods as well   in the class properties have implementations the  interfaces cannot be instantiated these are more   like contracts in our application if there  is an object that implements the interface   the object is definitely going to have all  the properties and methods defined in the   interface however a class can be instantiated  each instance of a class has all the properties   and methods defined on the class now taking a  simple real-world analogy for interface and class   let's say i have a person now i don't have much  detail about this person just that it has a name   and age so this person is much like an interface  which has created a contract to have a name   and age but the details are not in yet  however if i go into the detail of a person   let's say he is a lawyer this will  carry more details about this person   he is definitely a person but now his name and age  is defined with that he has a specific profession   and we also know about his workplace or he  might be a sports person with all the details   so for such detailed representation we use  classes and instantiate objects for them hence   we use interface when we want to  define the shape of the object   with no details we can use this shape in different  parts of our application in different ways if we   need to define a list of properties which we  can use to define a particular type of object   then we use interface let us now dive deeper into  interfaces in typescript and use it in our demo
Info
Channel: Smartherd
Views: 3,206
Rating: undefined out of 5
Keywords: smartherd, what is interface, what is class, structural type system in typescript, constructor functions, readonly properties, typescript demo web app, math problem project, creating custom types in typescript, extending class, implementing interface, static members, typescript demo, typescript tutorial for beginners, angular with typescript, annapurna agrawal
Id: 9fzf68qOW2E
Channel Id: undefined
Length: 3min 27sec (207 seconds)
Published: Sat Jun 04 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.