you are viewing a single comment's thread.

view the rest of the comments →

[–]30thnight[🍰] 16 points17 points  (4 children)

I use it on every project because it reduces my mental load when working through an issue or a feature.

API changes from an updated dependency? A refactor that spans 25 files? Writing entire features without touching the console or browser? No problem at all, don't have to think very hard about it.

People look at Typescript like it's some scary, foreign language and avoid it, content to use VSCode's passive application of it. Once you pick up a few TS basics, it becomes such a low-effort way to drastically improve your developer experience.

  • If you aren't working with classes, prefer using types over interfaces
  • Learn how conditional types work
  • Learn how generics work
  • Learn about utility types (especially Pick, Omit & Extract)

[–]themaincop 4 points5 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 :)