Interface vs Type in typescript

preview_player
Показать описание
Welcome to a youtube channel dedicated to programming and coding related tutorials. We talk about tech, write code, discuss about cloud and devops. That’s what we do all day, all year. We roll out a lot of series and videos on our channel.

All the learning resources such as code files, documentations, articles and community discussions are available on our website:

You can find our discord link, github link etc on the above website.

Рекомендации по теме
Комментарии
Автор

00:01 Interfaces have similarities with types but also have their unique features.

00:42 Adding missing properties to an interface in TypeScript

01:22 Passing input parameters in TypeScript using interfaces

01:59 TypeScript interfaces allow for easy code reuse

02:37 In TypeScript, you can use the 'extends' keyword to inherit properties from another class.

03:24 TypeScript interfaces can be extended and inherited

04:01 The difference between Type and Interface in TypeScript

04:39 Interfaces in TypeScript allow for adding new fields, while types cannot be changed after creation.

Great lesson sir thanks a lot.

SarveshKumar-
Автор

Very few people but genuine audience. Thank You!!

technicalom
Автор

When the compiler encounters multiple interface declarations with the same name, it merges them into a single interface definition that includes all the properties and methods from each declaration. Interface reopening is particularly useful when working with external libraries or modules. It allows you to extend or augment the types provided by those libraries without modifying their original definitions.

AbhishekShandilya-qc
Автор

Hitesh i think this the best playlist on typescript on youtube

shreyasdongare
Автор

From previous video, i was searching for difference between type and interface.
And now here it is. ❤️❤️

ksaha
Автор

Now i know what's different in between Interfaces and Type 👍

imamansoni
Автор

thank you sir, finally i found the exact difference between interface and type

vishalthapa
Автор

Keep pushing this content, I am eagerly waiting for the next video.

sundeeep
Автор

Beautifully explained, waiting for more videos in this series bhaiya🥰🥰

Vikas-dmuc
Автор

So interface is sort of like 'let' and type is sort of like 'const', correct? Am I understanding that correctly?

TJMcCarty
Автор

Sir ek video banao na ki
Bina degree ke software engineer kaise bante hai ?
Aur kya badi badi company Leto hai kya software engineer ko Bina degree wale pas uss bande mey sab skills hai

dcodgaming
Автор

Hello sir, can you suggest me a good source to learn sailpoint, by the way video was so understandable as usual

SanthoshKumar-fgzd
Автор

Sir ineuron website pr apke course purchase karne ke liye active coopen. Bta dijiye sir

narendranamdev
Автор

Interface vs. Type in TypeScript

TypeScript offers two main ways to define custom data structures: `interface` and `type`. While they share some similarities, they also have distinct characteristics and use cases.

**Interfaces:**

1. **Object Shapes:** Interfaces are primarily used to define the shape of an object or the contract that an object must adhere to. They are ideal for defining the structure of objects, especially when modeling classes or instances.

```typescript
interface Person {
name: string;
age: number;
}
```

2. **Class Implementations:** Interfaces can be implemented by classes, ensuring that the class adheres to the structure defined by the interface.

```typescript
interface Animal {
name: string;
speak(): void;
}
class Dog implements Animal {
constructor(public name: string) {}
speak() {
console.log(`${this.name} barks.`);
}
}
```

3. **Extending Interfaces:** You can extend interfaces to create new interfaces that inherit properties and methods from existing ones.

```typescript
interface Employee {
name: string;
}
interface Manager extends Employee {
department: string;
}
```

**Types:**

1. **Unions and Intersections:** Types are more flexible when it comes to creating complex types by combining multiple types using union (`|`) or intersection (`&`) operators. They are useful for creating complex and flexible type compositions.

```typescript
type Person = { name: string; age: number };
type Address = { city: string; postalCode: string };
type Contact = Person & Address;
```

2. **Primitive Types:** Types are often preferred when defining simple types like strings, numbers, booleans, or literal types.

```typescript
type Status = "active" | "inactive";
```

3. **Mapped Types:** You can create new types based on the properties of existing types using mapped types with types.

```typescript
type Optional<T> = { [P in keyof T]?: T[P] };
```

4. **Utility Types:** TypeScript provides built-in utility types like `Partial`, `Record`, `Pick`, and `Omit` that work naturally with types.

```typescript
type PartialPerson = Partial<Person>;
type RecordOfPersons = Record<string, Person>;
```

**Scholarship Opportunity:**


In summary, the choice between `interface` and `type` in TypeScript depends on your specific use case and how you want to model your data and code structure. Both `interface` and `type` have their strengths, and understanding when to use each can help you write more maintainable and expressive TypeScript code.

GildwareTechnologies
Автор

Why no videos are coming @hitesh sir ?

arunjoshi