Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fahad salamat randhawa #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions step20c_constructor/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(); //
Expand All @@ -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:
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions step26_interfaces/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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



Expand Down
2 changes: 1 addition & 1 deletion step36c_reflection/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down