People call me Noah.
// CreaturesBase: installed through 'npm install creatures-base'
export default abstract class Animal {...}
We have this abstract base class called Animal
, which comes from a third-party package on npm
. Other packages extend it as follows:
// planetX - brought in with 'npm install creatures-planetX'
import Animal from 'creatures-base'
export class Alien extends Animal {...}
export class Robot extends Animal {...}
export class SpaceDog extends Animal {...}
...
My task involves gathering all species of animals at runtime, but the challenge is that I don't always know which planet I'll be working on:
// andromeda - obtained by 'npm install creatures-andromeda'
import Animal from 'creatures-base'
export class AlphaAlien extends Animal {...}
export class BetaAlien extends Animal {...}
export class GammaAlien extends Animal {...}
...
There are shifts where I might have to work across multiple planets...
Query One:
Can we create a function to achieve this?
function compileAllAnimals() : [Animal] {
return [ /* Array containing one instance of each animal type */ ]
}
Query Two:
If the above is feasible, can we also determine the native planets of these animals?
function compileAllAnimals(fromPlanet) : [Animal] {
return [ /* Array containing one instance of each animal native to 'fromPlanet' */ ]
}