I am facing an issue with this particular function
function getCollection<T>(collectionType: T): Collection<T> {
return new Collection<T>()
}
In the Collection
class, I have the following code snippet
export class Collection<T> {
public add (item: T) {
// .. logic
}
}
Additionally, I have a user class named as follows
export class Student {
}
When trying to execute the following line of code
getCollection(Student).add(new Student());
I encounter an error message
TS2345: Argument of type 'Student' is not assignable to parameter of type 'typeof Student'. Property 'prototype' is missing in type 'Student' but required in type 'typeof Student'.
However, the following code snippet works perfectly fine
new Collection<Student>().add( new Student());
Hence, what could be causing the issue when the function returns a generic collection?