From ece2eb11355d74c458ee72b6544fafec168bf633 Mon Sep 17 00:00:00 2001 From: FahadSalamatRandhawa Date: Mon, 24 Oct 2022 19:43:59 +0500 Subject: [PATCH 1/3] Added changes to step20c-constructors 'super must be on first line' --- step20c_constructor/app.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/step20c_constructor/app.ts b/step20c_constructor/app.ts index 402bd1ae..5d4c610c 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: From e124d7ad6249f4eb22fff720837edbfe7f3624de Mon Sep 17 00:00:00 2001 From: FahadSalamatRandhawa Date: Mon, 24 Oct 2022 19:48:45 +0500 Subject: [PATCH 2/3] Added changes to step20c-constructors 'super must be on first line' --- step20c_constructor/app.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/step20c_constructor/app.ts b/step20c_constructor/app.ts index 5d4c610c..2342d635 100644 --- a/step20c_constructor/app.ts +++ b/step20c_constructor/app.ts @@ -61,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 From 1889c0f456976d0f633c799579755613e5157040 Mon Sep 17 00:00:00 2001 From: FahadSalamatRandhawa Date: Fri, 28 Oct 2022 15:12:12 +0500 Subject: [PATCH 3/3] changes in 20c 26 and 36c added some comments and examples --- step20c_constructor/app.ts | 2 +- step26_interfaces/app.ts | 9 +++++---- step36c_reflection/app.ts | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/step20c_constructor/app.ts b/step20c_constructor/app.ts index 2342d635..12e84826 100644 --- a/step20c_constructor/app.ts +++ b/step20c_constructor/app.ts @@ -32,7 +32,7 @@ class C { class D extends C { name:string; constructor(theName: string,age:number) { - //Super() must be here + //Super() //must be here this.name = theName; console.log("D constrcutor"); super(); // 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}`); }