D
D
dark_king_132021-01-24 16:27:20
typescript
dark_king_13, 2021-01-24 16:27:20

How to make a class available for type designation in any project file?

There is a Dom.ts file which contains the DomElement class and there are many other class files in which the constructor accepts an instance of the DomElement class or methods accept/return it. And I have to import it in all these files, just to specify the type. Is there any other option?

I don't understand how .d.ts files work.
I declared in such a file and this type became available throughout the project. How to do the same with a class? type EventType = 'click' | 'input' | 'mousedown'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2021-01-24
@Kozack

  1. Describe interfacein file.d.ts
  2. In the place where you implement the class, add
    - class DomElement {
    + class DomElement implements [Название интерфейса] {
       // код класса
     }

  3. For the rest of the project, use the name of the interface

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question