samedi 27 mai 2017

How to know the members of a extended class in typescript

The following code let to know the names and the properties of the members of a class in typescript language:

export class Teacher 
{
   Id: number;
   Name: string;
}

var teacher = new Teacher();

for(p in teacher) 

{

 var typeField = null;

 switch (typeof (teacher[p])) 
 {

       case 'string':

         typeField = "String";
         break;

       case 'number':

         typeField = "Number";
         break;

       case 'object':

         typeField = "Date";
         break;

       case 'boolean':

         typeField = "Boolean";
         break;
      }

 .....
 .....
}

But if I extend the class in this way:

export class Person
{
   Id: number;
   FirstName: string;
   LastName: string;
}

export class Teacher extends Person
{
   Id: number;
   IdPerson: number;
   School: string
}

The previous code does not work correctly because it lists only some members but not all. Can someone propose me the solution to have the complete list of the members ? Thanks. M.P.





Aucun commentaire:

Enregistrer un commentaire