I have function that creates instances of given class and I don't how to tell TypeScript that:
function builder returns instances of class passed in first argument
class A extends HTMLElement {
color: 'white'
}
function builder<T extends typeof HTMLElement>(classParam: T) {
let instance = new classParam()
return instance
}
let instance = builder(A)
instance.color = 'black'
// Property 'color' does not exist on type 'HTMLElement'
Is it possible without using type assertion?
newan HTMLElement though, I don't understand what it is you're trying to do. Are you looking fordocument.createElement()by any chance?