DEV Community

Margaret W.N
Margaret W.N

Posted on

3 2

Day 45: Interfaces in Typescript

I wrote or rather ctrl + c and ctrl + v and Interface today. Which sparked my interest on understanding interfaces in typescript.

What are Interfaces?

An interface defines the form in which an object takes. Take an example of a work contract, it defines the code of conduct. Having signed the contract you have to adhere to the code of conduct. Interfaces are similar to this you define the options/ properties of an object, so anytime you use this interface you have to adhere to the defined form.

How do i create an interface?

interface person {
  firstName: string;
  isSleepy: boolean;
}
Enter fullscreen mode Exit fullscreen mode

How do i use an interface?

You pass in a parameter with the type of our declared interface me:person. The parameter will contain the properties of your interface.

const me:person = {
  firstName: Maggie;
  isSleepy: true;
}
//For a function
function myState(me: person){
  firstName: Maggie;
  isSleepy: true;
}
Enter fullscreen mode Exit fullscreen mode

I really enjoyed Harry Wolf's video content:

I found interfaces really similar to classes, which gets me wondering, what is the difference between the two?

Day 45

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay