News for hackers. Stuff that matters.
Re:Node.js adds experimental support for TypeScript by dobladov on Thursday July 25, 2024 @04:02AM (#41066034)
You can have this now adding types with JSDoc and validating them with typescript without compiling, you get faster builds and code that works everywhere without magic or need to strip anything else than comments.

The biggest pain point of using JSDoc at least for me was the import syntax, this has changed since Typescript 5.5, and it's now not an issue anymore.

Re:Node.js adds experimental support for TypeScript by murmansk on Thursday July 25, 2024 @04:13AM (#41066120)
For god's sake, please stop shilling JSDoc as a TS replacement. It is not. If you encounter anything more complicated than `A extends B`, JSDoc is a pain in the ass of huge intensity to write and maintain.
Re:Node.js adds experimental support for TypeScript by adhamsalama on Thursday July 25, 2024 @04:20AM (#41066174)
You can write TypeScript types in JSDoc.
Re:Node.js adds experimental support for TypeScript by sureIy on Thursday July 25, 2024 @06:51AM (#41067055)
You can’t write complex TypeScript types in JSDoc, which is what GP said.

The moment you need to declare or extend a type you’re done, you have to do so in a separate .ts file. It would be possible to do so and import it in JSDoc, but as mentioned before it’s a huge PITA on top of the PITA that writing types can already be (e.g. function/callbacks/generics)

Re:Node.js adds experimental support for TypeScript by dobladov on Thursday July 25, 2024 @04:38AM (#41066289)
You should write complex types in interfaces files where they belong, and there's full typescript support.

I use this approach professionally in teams with many developers, and it works better for us than native TS. Honestly give it a try, I was skeptical at first.

Re:Node.js adds experimental support for TypeScript by rty32 on Thursday July 25, 2024 @06:51AM (#41067060)
In general JSDoc is just much more verbose and has more friction, even outside complex types. I recently finished a small (20 files/3000 lines), strictly typed JS project using full JSDoc, and I really miss the experience of using the real TypeScript syntax. Pain points: annotating function parameter types (especially anonymous function), intermediate variable type and automatic type-only import, these are the ones that I can remember. Yes you can get 99% there with JSDoc and .d.ts files, but that's painful.
Re:Node.js adds experimental support for TypeScript by dobladov on Thursday July 25, 2024 @09:38AM (#41068560)
I use snippets to write those, yes it's more verbose there's not denying that.

For me the advantages of just having JS files and not worrying about more complex source-maps, build files, etc definitely makes it worth it.

Re:Node.js adds experimental support for TypeScript by FractalHQ on Thursday July 25, 2024 @04:10PM (#41072832)
Source maps and build files are automatically generated when bundling which you need to do with or without typescript… so this argument always confuses me. There is no tangible downside in my experience.. either way it’s just typing “pnpm build”.
Re:Node.js adds experimental support for TypeScript by afavour on Thursday July 25, 2024 @07:54AM (#41067524)
I’ve had a lot of success combining JSDoc JS with .d.ts files. It’s kind of a Frankenstein philosophically (one half using TS and one half not) but the actual experience is great: still a very robust type system but no transpiling required.

In a world where ES modules are natively supported everywhere it’s a joy to have a project “just work” with zero build steps.

Re:Node.js adds experimental support for TypeScript by flanbiscuit on Thursday July 25, 2024 @04:02PM (#41072750)
I do this as well. JSDoc is great for simple definitions, but as soon as you want to do something more complicated (generics, operators, access types, etc) you get stuck. The .d.ts are ignored because you're only importing them within JSDoc comments.
Re:Node.js adds experimental support for TypeScript by Waterluvian on Thursday July 25, 2024 @08:36AM (#41067920)
Jsdoc is honestly fine for simple and smaller projects. But yeah, it’s definitely not nearly as expensive while being anywhere as succinct.
Re:Node.js adds experimental support for TypeScript by yard2010 on Thursday July 25, 2024 @12:18PM (#41070429)
JSDoc is for docs, TypeScript is a static type checker. How can these tools be used interchangeably?
Re:Node.js adds experimental support for TypeScript by styfle on Friday July 26, 2024 @11:10AM (#41079245)
You can configure tsconfig.json to read JSDoc and error on invalid types so that you effectively get the same behavior as writing typescript.
Re:Node.js adds experimental support for TypeScript by meiraleal on Thursday July 25, 2024 @09:32AM (#41068499)
Dude you are shilling adding a compile phase to a dynamic language and think that's smart! Stop telling people to not talk about JSDoc.
Re:Node.js adds experimental support for TypeScript by tracker1 on Thursday July 25, 2024 @11:06AM (#41069554)
JSDoc is also helpful in dealing with multiple argument option types for a function or constructor, which won't show in TS alone.
Re:Node.js adds experimental support for TypeScript by sroussey on Thursday July 25, 2024 @12:02PM (#41070230)
Re:Node.js adds experimental support for TypeScript by itsmeste on Thursday July 25, 2024 @05:54AM (#41066750)
I strongly agree, but JSDoc isn't "the cool thing". So it's left to be used by us, who care (and read their docs).
Re:Node.js adds experimental support for TypeScript by llimllib on Thursday July 25, 2024 @09:31AM (#41068484)
The auto-export of declared types was what killed it for me
Re:Node.js adds experimental support for TypeScript by epolanski on Thursday July 25, 2024 @08:40AM (#41067965)
JSDoc absolutely does not scale and allows for very limited type programming.

It's fine on toy projects, and somewhat I would say, for 99% of users that don't even know what a mapped or intersection type is.

Re:Node.js adds experimental support for TypeScript by mablopoule on Thursday July 25, 2024 @09:39AM (#41068565)
JSDoc does not scale, but some projects are just better when they aren't scaled.

JSDoc is indeed fine on toy project, or in fact any project (even prod-ready ones) that doesn't warrant the trouble of adding NPM packages and transpilation steps.

Although they are rare, those type of small, feature-complete codebases do exists.

Re:Node.js adds experimental support for TypeScript by eezing on Friday July 26, 2024 @01:48AM (#41076089)
Good for annotating js files here and there, but lousy dx.