Difference between extending and intersecting interfaces in TypeScript?

Yes there are differences which may or may not be relevant in your scenario. Perhaps the most significant is the difference in how members with the same property key are handled when present in both types. Consider: interface NumberToStringConverter { convert: (value: number) => string; } interface BidirectionalStringNumberConverter extends NumberToStringConverter { convert: (value: string) => … Read more

Generics : List

List<Dog> is a subtype of List<? extends Animal>, but not a subtype of List<Animal>. Why is List<Dog> not a subtype of List<Animal>? Consider the following example: void mySub(List<Animal> myList) { myList.add(new Cat()); } If you were allowed to pass a List<Dog> to this function, you would get a run-time error. EDIT: Now, if we use … Read more

Extending an Object in Javascript

You want to ‘inherit’ from Person’s prototype object: var Person = function (name) { this.name = name; this.type=”human”; }; Person.prototype.info = function () { console.log(“Name:”, this.name, “Type:”, this.type); }; var Robot = function (name) { Person.apply(this, arguments); this.type=”robot”; }; Robot.prototype = Person.prototype; // Set prototype to Person’s Robot.prototype.constructor = Robot; // Set constructor back to … Read more