Live data from Hacker News

TS to JSDoc Conversion

github.com

151–160 of 163 posts

Re: TS to JSDoc Conversion

#151
post #25

For anyone who is still confused - they're still gonna be using TypeScript in that they will have a tsconfig.json, `allowJS: true, checkJS: true` but they are just writing the files in JS with JSDoc type annotations, they'll still have `.d.ts` files to allow TS developers to use it without issues. Is it contrarian - yes - is it insane - no, not really. Edit: the motivation seems to be to simplify processes - running…

It really doesn't look like that big of a change as well. Looking at the PR, they didn't go too heavy on their typescipt usage. I can see they when using typescript, they added types for function parameters, but not for return types, for example.

Re: TS to JSDoc Conversion

#152

Earlier quoted context omitted.

> It's also a really contrarian viewpoint about typescript which is really popular. I really, really don't get the controversy here. JSDoc _is_ TypeScript, just with a syntax that's valid JavaScript (on account of it living in comments). This means it doesn't have to be built to run, but still gets all of the typing goodies regular TypeScript does. The end-user code authoring experience is the same or better. > To co…

> JSDoc _is_ TypeScript No. At least, it didn't used to be. JSDoc had its own syntax, but now you can piggyback its format and put TypeScript inside. So now you can write `@type {Record }` instead of the "classic" `@type {Object. }`, and use some more TypeScript goodies. You can even kind of use generics with JSDoc, still thanks to TypeScript, but then again... you're not really leaving TypeScript, you'll still have…

JSDoc TS is well documented: https://www.typescriptlang.org/docs/handbook/jsdoc-supported...

It's not 1:1 in features though, but because you can import definitions https://www.typescriptlang.org/docs/handbook/jsdoc-supported... you can use a file a part whenever you encounter any of those advanced features / edge cases current JSDoc does not support.

Like other said, it's still TS after all, and there are escape hatches when needed.

In so many projects I use JSDoc TS, the amount of projects that ended up needing a manual .d.ts file not utomatically generated via `tsc` can be counted in half hand.

Maybe people could give it a try, after all if you comment a method, beside its signature and return types, you can as well just move types in there ;-)

Re: TS to JSDoc Conversion

#153

Earlier quoted context omitted.

Just jumping in here to applaud the usage of "luddite numpties" in a sentence.

When I try to google this, the top (and only relevant) result is this hn post… mind throwing a bone?

Search for the definition of the two words individually and you'll be good!

Re: TS to JSDoc Conversion

#154

Earlier quoted context omitted.

> Lordy, I did not expect an internal refactoring PR to end up #1 on Hacker News. Let me provide some context, since a lot of people make a lot of assumptions whenever this stuff comes up! Because people want to follow in the footsteps of big projects that have gained specialized knowledge through experience. It's also a really contrarian viewpoint about typescript which is really popular. tbh, this seems pretty far…

> It's also a really contrarian viewpoint about typescript which is really popular. I really, really don't get the controversy here. JSDoc _is_ TypeScript, just with a syntax that's valid JavaScript (on account of it living in comments). This means it doesn't have to be built to run, but still gets all of the typing goodies regular TypeScript does. The end-user code authoring experience is the same or better. > To co…

> JSDoc _is_ TypeScript

This is surprisingly true in a way. TypeScript is not a language(1), it's primarily a linter-assisting overlay atop of an actual language, JavaScript. Also, there's a linter that outputs and bundles JS, shedding the alien type annotations and also injecting its own, very partial runtime.

So, JSDoc is just a linter/documenter aid. And so is TypeScript.

(1) TS is not a language: it has no spec, no reference documentation. It defines no behaviors, in particular, no runtime behaviors. It sits atop of various JS versions, layering over them in unspecified ways. TS is a linting layer, and also is a hack.

Re: TS to JSDoc Conversion

#155

Earlier quoted context omitted.

> JSDoc _is_ TypeScript No. At least, it didn't used to be. JSDoc had its own syntax, but now you can piggyback its format and put TypeScript inside. So now you can write `@type {Record }` instead of the "classic" `@type {Object. }`, and use some more TypeScript goodies. You can even kind of use generics with JSDoc, still thanks to TypeScript, but then again... you're not really leaving TypeScript, you'll still have…

JSDoc TS is well documented: https://www.typescriptlang.org/docs/handbook/jsdoc-supported... It's not 1:1 in features though, but because you can import definitions https://www.typescriptlang.org/docs/handbook/jsdoc-supported... you can use a file a part whenever you encounter any of those advanced features / edge cases current JSDoc does not support. Like other said, it's still TS after all, and there are escape hat…

That's an interesting hybrid approach, thanks Andrea.

Is this what Svelte will use? (Asking anybody that knows, of course.)

Anyway, to me the main problem in using TS with libraries is that we have 3-4 major releases per year, and they're just too many. Unless one takes a very restrained approach, releasing very generic (and thus less helpful) types that won't (presumably) break future (or past) versions of TypeScript, we need to release with `typesVersions` targetting n different versions of TypeScript. That's an ever-growing bother indeed for maintainers as time passes.

And I fear the hybrid approach above won't escape this issue. So using "pure" JSDoc or JSDoc with just a sprinkle of TypeScript actually makes sense... But I'd expect this workflow to be winning with smaller projects, and that's why this announcement for Svelte has been surprising to me.

Re: TS to JSDoc Conversion

#156

Earlier quoted context omitted.

> tbh, this seems pretty far out there. Sourcemap file size is a non-issue, they're not gigabytes Sure, by themselves, but replicate that across everyone repeatedly downloading the library in various build processess, in various projects and with different versions. Sure, by itself a sourcemap might not add up to much. But then there is various projects with different versions, who download the library repeatedly in…

> it starts to add up both in bandwidth, and in storage taken Are we really talking about disk space in 2023? Seriously? And bandwidth? Like we don't have several cache systems - including npm's - that can help? > how to make your software easier to change in the future Ok, is there someone who can explain in details how would that help?

> Are we really talking about disk space in 2023? Seriously?

Well, it adds up, if you're doing multiple projects.

Doing a quick scan of my work desktop, I find 43,237 filenames matching ".js.map". The biggest is at ~10,000 KB, the smallest at 1KB. If we assume the average is just 200KB, in total they represent ~8.6 gigabytes (200 kilobytes 43237). That's not nothing.

> And bandwidth? Like we don't have several cache systems - including npm's - that can help?

Being conservative with bandwidth is a good thing for most. Not only will everything download faster because less is needed, but it'll probably be cheaper for you to run your application as serving less bandwidth either gives you a small bill if you use cloud, or requires less hardware if you're going the dedicated route.

Not to mention not everyone sits with the latest maxxed out Apple hardware for working, especially outside the SV bubble. These people deserve to be able to have a good development environment as well.

Overall, everything gets faster and cheaper if you save bandwidth.

> Ok, is there someone who can explain in details how would that help?

It's easy, the lesser moving parts your application has in the abstraction ladder, the safer and easier it gets to change things in the future.

Transpiling from one language to another to get a benefit you can also get by not transpiling a language from one to another, seems like a no-brainer to me in most cases.

Re: TS to JSDoc Conversion

#158
post #139

Earlier quoted context omitted.

What if TypeScript could compile to JS/JSDoc instead of source maps? I'm also not a fan of 'go to definition' bringing me to a dead end d.ts file, but also there has to be a better solution than verbosely JSDoc'ing all the things.

There was talk about introducing type syntax as valid but ignored in the JS language, making TS valid JS. It would take forever to become mainstream but if node and major browsers started to support this tomorrow, along with ESM modules we could drop TS compilation and bundling entirely during development, safely publish npm packages as TS (even a bundled TS) and simplify tooling for monorepos, IDEs, etc. Unfortunate…

Right yea that solution would be many years out and doesn't work for JSX. As opposed to compiling to JS/JSDoc which could be done today and should solve our problems with stepping into NPM package code without dead ends.

Re: TS to JSDoc Conversion

#159
post #35
post #19

If I remember right, symfony (php framework) has comments that affect how the code runs which as far as I’m concerned means they’re not comments at all but actually code masquerading as comments. Reading about JSDoc gives me the same uneasy feeling, even if it’s not quite the same thing. Edit: Here’s one example, you can define your routes in symfony using comments. Not only that, but it’s actually the officially rec…

I don't see any comments there, I see attributes though [1]. Is that what you meant? From the page you linked: > Routes can be configured in YAML, XML, PHP or using attributes. All formats provide the same features and performance, so choose your favorite. Symfony recommends attributes because it's convenient to put the route and controller in the same place. Attributes are not comments, they are an official structur…

Attributes are a newish thing in Php that got created because people were using comments as code. And yeah, before attributes Symfony would use comments to define routes right above the function definition.

Re: TS to JSDoc Conversion

#160

Lordy, I did not expect an internal refactoring PR to end up #1 on Hacker News. Let me provide some context, since a lot of people make a lot of assumptions whenever this stuff comes up! If you're rabidly anti-TypeScript and think that us doing this vindicates your position, I'm about to disappoint you. If you're rabidly pro-TypeScript and think we're a bunch of luddite numpties, I'm about to disappoint you as well.…

I've been doing exactly the same thing for a number of years, and I find it a much more intuitive way to use TypeScript.

First, to ensure a focused discussion, I think it's a good idea to separate out TypeScript the transpiler, TypeScript the language, TypeScript the type-checker, and by extension, TypeScript 'types'.

Personally, I don't like transpilers. I never liked CoffeeScript and I hate not being able to see the 'actual' code when looking inside a Docker image in a K8s cluster. I also don't like using non-standard features in a language; I'd far rather live without something that is TS-specific, and if it turns out that this feature has legs, then just wait for it to be included in vanilla JS. (Not to mention that it smacks too much of vendor lock-in, for not much benefit.)

But I do get that this is to some extent because I'm primarily coding to Docker images, rather than multiple browsers. If I want to bump the version of Node to get some new feature, it's pretty easy. So I do recognise that for people working on the client side, where bundling and source maps and all that other chaos is the norm, then transpiliation is no big deal.

(Having said that, back in the day we all used to love that you could hack away on a web app using files on a file system, just loading HTML, JS, and CSS... It's a shame that we seem to have lost the 'vanilla first' approach to software, and leap to preprocessors for everything.)

Anyway... my first point is simply that TypeScript as a _transpiler_ doesn't have any appeal to me.

But I'm not about to throw the baby out with the bath water.

As with the original post, I love types! I think TS types are the best thing to happen in years. Where possible I like to use declaration files as the single source of truth (type first development). From there you can generate GraphQL and OpenAPI schemas, use them to drive contracts for implementation, share the files with other developers using other languages, and so on. And as with this post, I make the connection between the types in the declaration files and the code in the JS files, primarily through inference, and then as necessary through JSDoc.

As with many things, there is going to be a lot of personal preference to this. Since I like the way that Haskell puts type information on a separate line to the function that is being described, it's probably no surprise that I also find the JSDoc approach of putting the types in separately more intuitive.

And since it's easy to configure an editor/IDE to use TSC to lint and provide intellisense on JS files, you can get all of the advantages of TypeScript without having to transpile.

That seems like I pretty good deal to me!

Post reply on HN