Transitioning to Typescript has brought me immense joy for various reasons.
While exploring its benefits, I encountered a challenge related to verifying if an argument passed to a function extends another class.
Here is an example scenario:
class Foo {
public $xyz
}
class Bar {
constructor(model: extends Foo)
}
class Baz extends Foo {}
Multiple classes can extend foo, not just Baz, but they all share the same properties. To ensure that the class passed to the model
parameter of the Bar
constructor correctly extends Foo
, how can this be accomplished?
(excuse the rough pseudo-code provided)
If my approach is flawed, I am open to suggestions on how to overcome this issue.