DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Do you use TypeScript with projects only you will touch?
Junior Batista
Junior Batista

Posted on

Do you use TypeScript with projects only you will touch?

It's very easy to see the benefits of using TypeScript in projects with multiple programmers. Is it still worth it if you're the only one that will ever touch that project?

Top comments (11)

Collapse
 
jamesvanderpump profile image
James Vanderpump

Of course. If you come back to a project in a couple of months, you will be very pleased you wrote some types and interfaces around your classes/functions. You probably come back for a quick refactor, tada!, this is now super trivial and you are probably done much faster and can go out for a drink with your friends instead of starting up the debugger.

Collapse
 
pengeszikra profile image
Peter Vivo

I'm on early phase of typescript use. I wittingly change my default - hobby - languages from JS to TS. That process sometimes faces some difficulty, on the contrary definitions part is really help, even middle sized project.

But sometimes I found TS is don't really understund every JS declaration.

For example:

interface Message { 
  id:string; 
  msg: string; 
  name?: string;
  avatar?: string;
}

type TBlogMap = (content:Message, index:number, list:Message[]) => Message;

// JS is fine but TS dosent know the ...rest part - which is obviously: {id, msg}
export const blogSameUserHeaderMap:TBlogMap 
= ({name, avatar, ...rest}, index, postList) => postList?.[index - 1]?.name === name
  ? {...rest}
  : {name, avatar, ...rest}
;

// working version
export const blogSameUserHeaderMap:TBlogMap 
= (content, index, postList) => postList?.[index - 1]?.name === content?.name
  ? ({msg:content.msg, id: content.id})
  : content
;
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jesusantguerrero profile image
Jesus Guerrero

For my TS is not my default option because most of the projects I start is for solving a problem I currently have and I need to advance fast. But if is a short project like a library that I am starting with TS to build the habit and not getting bored.

Collapse
 
noxasch profile image
Alexander Dischberg

JSdoc with minimal typescript to utilized the typehint and lint for personal project since i work with other language as well and it makes more sense to me. eg: ruby YARD, python docstring, dart doc comments, javadoc.

Collapse
 
marcel_cremer profile image
Marcel Cremer

Sure, typing is kind of a documentation and a safety net at the same time. Usually the projects who were not "worth the effort" to be initialized with it, are the ones that are timewasters anyway - especially if you have plenty of boilerplates available to make the setup super fastπŸ™‚

Collapse
 
brense profile image
Rense Bakker

Why would you not start with TS? Just copy paste a tsconfig into your JS project and tada now its a TS project

Collapse
 
dennistobar profile image
Dennis Tobar

Sure, the code could have less errors and you could read it in the future and still understand your code (before smile and rewrite it πŸ˜‰)

Collapse
 
nstvnsn profile image
Nathan Stevenson • Edited on

Trying to. I like maintaining good habits, as they are hard to form in the first place. I am liable to use my indicators when I'm the only one on the road too, though, so I'm just weird 😁

Collapse
 
miketalbot profile image
Mike Talbot

No chance I'd use TypeScript on smaller things, can't be bothered to type all the extra bloat if only I or a few people will work on it.

Collapse
 
jonrandy profile image
Jon Randy

I personally don't see the benefits at all - personal project or otherwise

Collapse
 
nikfp profile image
Nik F P

Always, unless it's literally a 10 line scratch file to test something.

I find that on anything I work on that is non-trivial, it's much easier to take the time to get the TS right on object types and function inputs and output, and then use the type system later when I consume those same types. It means less mental overhead for me, and ultimately I move faster as a result.

I see a lot of people taking issue with the need to write out interfaces and types. I find that using the type inference system and utility types that TS provides gets me around about 80% of that, so in the end I'm really only specifying types for function inputs and that's about it. Output types are inferred, so if I make a breaking change in a function the TS compiler yells at me where I use it, and I know to fix the issue or fix it where it's implemented.

πŸ€” Did you know?

Β 
✍️ Writing your own article is easy (we even support markdown)