#How does this work?

15 messages · Page 1 of 1 (latest)

heady wagon
#

I have a base class, that is extended in multiple different classes
and i have an array that houses a bunch of different objects contructed from those different classes.
So now i want to have a function where i can give a class as an input and then get all the elements of the array that got constructed from that class.

class Test {}
class TestA extends Test {}
class TestB extends Test {}
class Testc extends Test {}

let array: Test[] = [];

// randomly add TestA, TestB, TestC

function getOfType(type: ???): Test[] {
  // magically get all of the ones that are of that type
}

// expected:
getOfType(TestA) // -> [TestA, TestA, TestA]```
next star
#

you'd just put Test

heady wagon
#

where would i put test?

heady wagon
empty karma
#

are you asking about the types or the values?

heady wagon
#

just added a type string thingy

#

on all of the classes

#

and that worked aswell

#

probably not as clean but it gets the job done

#

thanks tho

empty karma
#

im still confused what your question was lol

empty karma
heady wagon
#

i would like that yes

empty karma
#

then could you answer my question and provide some more context on what exactly you're asking about?

#

are you trying to get all instances of the class? or just filtering some array?