DEV Community

Discussion on: Creating your first Node.js REST API with Nest and Typescript

Collapse
 
bidipeppercrap profile image
Fransisco Wijaya

Why did you use interface instead of class on DTO?

Collapse
 
softchris profile image
Chris Noring

Hi Fransisco. I tend to use interfaces when all I need is shape, i.e something containing a few properties that belong together. If I can't motivate that I will instantiate it at some point an interface is a good way to start. If a find, later on, I need to create an instance of it then I will switch it to a class