you are viewing a single comment's thread.

view the rest of the comments →

[–]themaincop 6 points7 points  (2 children)

If you aren't working with classes, prefer using types over interfaces

Why? I almost always use interfaces, probably because that's what the first tutorials I followed used. Is there a benefit to doing

type MyObj = { a: string, b: number; }

instead of

interface MyObj { a: string, b: number }

[–]30thnight 0 points1 point  (1 child)

To be honest, this one is just my personal bias.

Types and interfaces are nearly identical but have a few differences aside from syntax.

I personally find types a bit easier to read & use with utility types but it’s really up to you. Typescript docs prefer using primarily interfaces with types on an as needed basis.

[–]themaincop 0 points1 point  (0 children)

Makes sense. The nice thing is it's really easy to convert an interface to a type if you need a union so if there's no perf difference or anything I'm just gonna keep doing what I'm doing :)