L
L
lil_web2020-03-21 19:52:09
typescript
lil_web, 2020-03-21 19:52:09

How to stop polluting code with interface imports?

I'm writing a React web application using TypeScript.

I describe the props of a functional component using an interface. This interface is needed in other components or helpers, so you have to export and import it - clog the code.

In Flow, I just wrote declare type, and the type was available throughout the project. How to do the same in Typescript?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
abberati, 2020-03-21
@abberati

Global variables are bad. You did badly in the flow. But you can do the same in https://www.typescriptlang.org/docs/handbook/decla...

A
Aetae, 2020-03-26
@Aetae

You can just put some global.d.ts thread somewhere (in the directory included in tsconfig.json) and just throw frequently used interfaces there. )
But, of course, if the interfaces are associated with some modules, it is correct to store them in the corresponding modules. All the same, using the module, you import it, adding to the import also does not make the weather interface.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question