TypeScript में extends और implements: क्या अंतर है?
सभी को नमस्ते! मैंने अभी JavaScript के बाद TypeScript सीखना शुरू किया है और दो key words — `extends` और `implements` में उलझ गया हूँ। दोनों का उपयोग classes और interfaces के साथ काम करने के लिए होता है, लेकिन मुझे समझ नहीं आ रहा कि कब क्या apply करना चाहिए।
मेरे पास एक सरल `Animal` interface है, जो basic properties और methods को describe करता है:
```typescript
interface Animal {
name: string;
makeSound(): void;
}
```
और मैं एक `Dog` class बनाना चाहता हूँ। Examples में मैंने देखा है कि `extends` और `implements` दोनों का उपयोग किया जाता है:
```typescript
// Option 1: implements
class Dog implements Animal {
name: string;
constructor(name: string) {
this.name = name;
}
makeSound() {
console.log("Woof!");
}
}
// Option 2: extends (यदि कोई base class हो)
class AnimalBase {
name: string;
constructo