samedi 14 novembre 2020

How to retrieve class property types from a class type?

I have the following class:

class Animal {
  name: string
  age: number
}

I want to be able to retrieve the types of the class's properties without it being initialized. Here is how I expect to be using this:

function getClassPropertyTypes(classType) {
  // perform some magic
}

// The returned value should be either an array or object with the property key and its type
getClassPropertyTypes(Animal)




Aucun commentaire:

Enregistrer un commentaire