I
I
ivan05122020-08-13 18:42:31
typescript
ivan0512, 2020-08-13 18:42:31

Should you use type or interface?

As far as I understand, in the latest versions of ts type, an alias can do everything the same as an interface, with the exception of declaration merging.
Does this mean that if declaration merging is not required, then it is better to always use types, not interfaces, so that the code looks more uniform, or are there other thoughts on this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Robur, 2020-08-14
@ivan0512

Should you use type or interface?

What do you want
it's better to always use types, not interfaces, so that the code looks more uniform

If the general use of types will lead to more uniform code, then yes.
And in another project, it may turn out that the use of interfaces will lead to more uniform code.
In any case, uniformity is good. What brings you closer to him, so write.

A
Aetae, 2020-08-14
@Aetae

Thoughts are simple in fact: look to the root.
Use interfaces to describe interfaces, use types to describe types.
And no, it's not the same thing.
To exaggerate: an interface is a description of a data structure that occurs at the junction of the interaction of system components or different systems, is mainly used only at this very junction; type - these are the internal entities that the system operates on and which are found everywhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question