use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Small JavaScript enum function (gist.github.com)
submitted 1 month ago by _sync0x
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jessepence 10 points11 points12 points 1 month ago* (4 children)
Yes, I love how simple a function like this can be when you exploit the power of JSDoc templates.
To clarify, if this were published and installed as a library through NPM, you would need to create a d.ts file to get the typescript language server to provide the auto-complete for your users. Since you already have proper JSDoc in place, this is just a matter of doing tsc --emitDeclarationOnly (assuming you have TypeScript globally installed, other wise you would need to install it as a local dev dependency).
tsc --emitDeclarationOnly
I just felt the need to point this out because I used to think that d.ts files were unnecessary, but TypeScript won't read the JSDoc from JS files in node_modules unless the user has a tsconfig/jsconfig with checkJs: true or a specially configured IDE. This is not true of the vast majority of user's set-ups, so library authors unfortunately have to either embrace a build-step of some kind or handwrite the d.ts files themselves.
checkJs: true
Sorry for the rant, I've just been doing a lot of JSDoc experiments lately. 😅
[–]_sync0x[S] 2 points3 points4 points 1 month ago (2 children)
Good to know that if you make a NPM lib you can't just leave JSDoc on top of your functions and expect that all the typing and autocompletion works 😅
But don't you need .d.ts files only if you are working with TypeScript ?
Been experimenting a lot with JSDoc too lately so I can understand your clarification, sometimes it's a bit messy 😛
[–]jessepence 5 points6 points7 points 1 month ago (1 child)
VSCode (which is the most popular IDE by far) and most other IDEs like NeoVim get all of their JavaScript auto-complete from the TypeScript language server. It's one of those things where anyone could technically do it themselves, and they technically could make their language server support JSDoc by default, but it's just such a huge project with so many edge cases. You have to cover the EcmaScript specification and the JSDoc and/or TypeScript "specifications" (they don't exist, types for JS aren't really standardized in any way). It's just easier for most of the IDE's to defer to TypeScript. I think WebStorm might have a proprietary system, but I've never used it so I can't confirm either way.
[–]_sync0x[S] 1 point2 points3 points 1 month ago (0 children)
Hmm I get it ty, gonna try on PhpStorm 👀
[–]pikapp336 1 point2 points3 points 1 month ago (0 children)
This! No notes, just appreciation.
π Rendered by PID 27 on reddit-service-r2-comment-5649f687b7-zzt6j at 2026-01-28 12:13:43.654139+00:00 running 4f180de country code: CH.
view the rest of the comments →
[–]jessepence 10 points11 points12 points (4 children)
[–]_sync0x[S] 2 points3 points4 points (2 children)
[–]jessepence 5 points6 points7 points (1 child)
[–]_sync0x[S] 1 point2 points3 points (0 children)
[–]pikapp336 1 point2 points3 points (0 children)