I have an class which contain array.
let object=new DynamicARRAY()
object.add(12)
object.add("google") // This should not allowed
let object=new DynamicARRAY()
object.add("google")
object.add(12) // This should not allowed
once i set type of and array how it can maintain type of that array.
i have some thing like that
class DynamicArray {
add(value:string):Array<number>
add(value:number):Array<string>
add<T>(value:T):Array<T> {
let collection = new Array<T>()
collection.push(value)
return collection
}
}
but not show how i can move collection in class level and it maintain its type.
Need just hint on right direction.