D
D
dicem2021-12-07 16:51:09
typescript
dicem, 2021-12-07 16:51:09

How to define a property as a class that extends another class?

Please tell me how in TS how to define any class that extends let's say some kind of conditional RegExp ??
Like this:

class T extends RegExp {...}
class E extends RegExp {...}

interface ChtotoTam {
   f: любой класс который extends RegExp
}


Interested in this case f in the interface ChtotoTam

It is clear that can be defined as
interface ChtotoTam {
   f: T | E
}

But I would like this interface to automatically expand somehow if we have other classes that are extended by RegExp

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-12-07
@Lynn

Well, put it there RegExp. Any class that extends it will do.

interface ChtotoTam {
   f: RegExp
}

https://www.typescriptlang.org/play?#code/MYGwhgzh...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question