On the sections for creating the react app and express server Mosh creates interfaces instead of types. for example, from the express lecture 6- Parsing Request Bodies:
What is created:
interface CreateReminderDto {
title: string;
};
This could be a possible type:
type CreateReminderDto = {
title: string;
};
What is the advantage of creating these as interfaces? (and not as types)
I think both would work, but in practice an interface usually means “this object may have more fields, but we only care about these ones” whereas a type generally means “this object has exactly these fields and only these fields.”
There are a few other nuances for types and interfaces. For example, interfaces can be extended and implemented while types cannot (so interfaces are more OOP). Types can define certain arbitrary criteria like unions and tuples, etc.
In my opinion, you should probably use an interface unless you must use a type. That’s just my opinion though.