I have this function
function getCollection<T>(collectionType: T): Collection<T> {
return new Collection<T>()
}
and in Collection
class I have this
export class Collection<T> {
public add (item: T) {
// .. logic
}
}
I have a user class defined like this
export class Student {
}
and when I attempt to do
getCollection(Student).add(new Student());
There is an error
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'.
Following works fine.
new Collection<Student>().add( new Student());
So what is wrong when the function returns generic collection?