Hacker News new | ask | show | jobs
by danwee 1066 days ago
Agree with the sentiment (statically-typed languages are cool), but TS is not ideal. Is the best we have if you want something JS-like, but try to explain the following monstrosity to a junior colleague who's starting with TS in the context of web applications (using one of the most popular frameworks out there, NestJS):

     // a DTO that handles the creation of some kind of resource
      ...
     @IsArray()
     @ArrayMinSize(1)
     @IsString({ each: true })
     @ApiProperty({
       example: ['software', 'maths'],
     })
     tags: string[]
That's real code. Since the TS types gets erased when the code is transpiled to JS, one has to annotate the whole thing just to be sure the clients are not sending us invalid data. And the validation via annotations couldn't be more cumbersome. 90% of the code in the DTO file is annotations. Reminds me Java from 10 years ago.
1 comments

Is that typescript's fault though? Seems like a nestjs thing