diff --git a/step20c_constructor/app.ts b/step20c_constructor/app.ts index 402bd1ae..12e84826 100644 --- a/step20c_constructor/app.ts +++ b/step20c_constructor/app.ts @@ -25,11 +25,14 @@ let d: B = new B("C"); // Thsi is also not working // If parent class does not provide constructor and child class provide constrcutor then // child class must call super() within child's class constructor // call to super can be at any line in constructor unlike any other object oriented language with call to super must be as first line +//* Correction to above line, call to super must be on first line in the child constructor, otherwise you will get a warning while using "this" before super *// class C { + } class D extends C { name:string; constructor(theName: string,age:number) { + //Super() //must be here this.name = theName; console.log("D constrcutor"); super(); // @@ -38,6 +41,7 @@ class D extends C { let aa: C = new C(); // This is working as expected let bb: D = new D(); // This is not working because child class has its 2 argumnet constrcutor let cc: D = new D("C",8); // This is working as expected +let dc: D = new C(); //class C must have atleast all properties of class D to be assigned to type D // Case c: @@ -57,6 +61,7 @@ class E { class F extends E { name:string; constructor(theName: string) { + //must call super here this.name = theName; console.log("F constrcutor"); super(theName,4); // Must call super with two arguments diff --git a/step26_interfaces/app.ts b/step26_interfaces/app.ts index 3b75aad9..f6cc4775 100644 --- a/step26_interfaces/app.ts +++ b/step26_interfaces/app.ts @@ -19,10 +19,11 @@ printLabel({mylabel: "Size 10 Object"});//Case 2a missing or renamed property: E //Case 2b //A type can include an index signature to explicitly indicate that excess properties are permitted in with fresh objects: -function printLabelX(labelledObj: {[x: string]:any}) {////Note now 'x' can have any name, just that the property should be of type string +function printLabelX(labelledObj: {[x: string]:any}) {////Note now 'x' can have any name, just that the property name should be of type string console.log(arguments[0]); } -printLabelX({name: "Zia"});// Ok, `name` matched by index signature +printLabelX({name: "Zia Khan"});// Ok, `name` matched by index signature name: any +printLabelX({value: 2});// Ok, `value` matched by index signature value: any //Case 3 @@ -33,7 +34,7 @@ printLabel({size: 10, label: "Size 10 Object"});//Case 3 Fresh Literal: Error no //Stale Objects: - +// function decleration at the top //Case 1: var myObj1 = {label: "Size 10 Object"}; printLabel(myObj1);//Case 1 exact properties: OK @@ -86,7 +87,7 @@ printLabelY2({name: "Zia"});// Ok, `name` matched by index signature //Case 3 printLabelY({size: 11, label: "Size 11 Object"});//Case 3 Fresh Literal: Error no extra properties allowed - +printLabelY2({size: 11, label: "Size 11 Object"})//Case 3 extra properties allowed as Fresh Literal due to index signature diff --git a/step36c_reflection/app.ts b/step36c_reflection/app.ts index f136bf97..e6f03d45 100644 --- a/step36c_reflection/app.ts +++ b/step36c_reflection/app.ts @@ -6,7 +6,7 @@ import "reflect-metadata"; -function logType(target : any, key : string) { +function logType(target : any, key : string) { //targe=Demo{} key=attr1 var t = Reflect.getMetadata("design:type", target, key); console.log(`${key} type: ${t.name}`); }