shakedown.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A community for live music fans with roots in the jam scene. Shakedown Social is run by a team of volunteers (led by @clifff and @sethadam1) and funded by donations.

Administered by:

Server stats:

261
active users

#jsdoc

0 posts0 participants0 posts today
Egor Kloos<p>I love that I can add CSS custom properties to a Custom Element Manifest via JSDoc. Let's see if I can add the idents/keys as specific properties to a JSX style attribute object. <a href="https://mastodon.social/tags/css" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>css</span></a> <a href="https://mastodon.social/tags/jsdoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>jsdoc</span></a> <a href="https://mastodon.social/tags/cem" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>cem</span></a> <a href="https://mastodon.social/tags/webcomponents" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>webcomponents</span></a></p>
Aral Balkan<p>While working on porting the Small Technology Foundation web site¹ to Kitten², I took the opportunity to pull out base Model and Collection classes that I’ll likely end up including in Kitten proper:</p><p>• Model: <a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/Model.js" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/Model.js</span></a><br>• Collection: <a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/Collection.js" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/Collection.js</span></a></p><p>To see them in use, here’s the base Posts class (with RSS generation) that extends Collection:<br><a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/Posts.js" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/Posts.js</span></a> </p><p>And here’s the concrete EventPosts collection class that extends Posts:<br><a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/EventPosts.js" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/EventPosts.js</span></a></p><p>And the EventPost (showing an implementation of a calculated property):<br><a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/EventPost.js" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/EventPost.js</span></a></p><p>So all this is possible (persisting and reading back typed model collections, etc.) thanks to JSDB¹ (JavaScript database), a zero-dependency, transparent, in-memory, streaming write-on-update JavaScript database I wrote for the Small Web that persists to a JavaScript transaction log and is included as as first-class citizen in Kitten.</p><p><a href="https://codeberg.org/small-tech/jsdb" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="">codeberg.org/small-tech/jsdb</span><span class="invisible"></span></a></p><p>And if you want to know how the magic mapping of classes happens, see the Database App Module:</p><p><a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/database.js#L34" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/database.js#L34</span></a></p><p>PS. For a much gentler introduction to persistence in Kitten, see the Kitten Persistence tutorial:<br><a href="https://kitten.small-web.org/tutorials/persistence/" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">kitten.small-web.org/tutorials</span><span class="invisible">/persistence/</span></a></p><p>Enjoy! :kitten:💕</p><p>¹ <a href="https://small-tech.org" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="">small-tech.org</span><span class="invisible"></span></a><br>² <a href="https://kitten.small-web.org" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="">kitten.small-web.org</span><span class="invisible"></span></a></p><p><a href="https://mastodon.ar.al/tags/Kitten" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Kitten</span></a> <a href="https://mastodon.ar.al/tags/SmallWeb" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>SmallWeb</span></a> <a href="https://mastodon.ar.al/tags/SmallTech" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>SmallTech</span></a> <a href="https://mastodon.ar.al/tags/JavaScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JavaScript</span></a> <a href="https://mastodon.ar.al/tags/database" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>database</span></a> <a href="https://mastodon.ar.al/tags/JSDB" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDB</span></a> <a href="https://mastodon.ar.al/tags/typeSafety" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>typeSafety</span></a> <a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a> <a href="https://mastodon.ar.al/tags/closureCompiler" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>closureCompiler</span></a> <a href="https://mastodon.ar.al/tags/TypeScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>TypeScript</span></a> <a href="https://mastodon.ar.al/tags/workInProgress" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>workInProgress</span></a></p>
Aral Balkan<p>Almost another year has passed and it’s still not possible to use JSDoc and have the TypeScript LSP understand when you’re referring to a class and when you’re referring to an instance…</p><p>*sigh*</p><p><a href="https://github.com/jsdoc/jsdoc/issues/1349#issuecomment-1725400751" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/jsdoc/jsdoc/issues/</span><span class="invisible">1349#issuecomment-1725400751</span></a></p><p><a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a> <a href="https://mastodon.ar.al/tags/TypeScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>TypeScript</span></a> <a href="https://mastodon.ar.al/tags/web" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>web</span></a> <a href="https://mastodon.ar.al/tags/dev" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>dev</span></a></p>
🧿🪬🍄🌈🎮💻🚲🥓🎃💀🏴🛻🇺🇸<p>If using Typescript means you want to write less Unit Tests then, actually, I'm all for it. Type away, with JSDoc comments.</p><p>But I'm still making you write end-to-end functional browser tests. </p><p><a href="https://mastodon.social/tags/typescript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>typescript</span></a> <a href="https://mastodon.social/tags/unitTests" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>unitTests</span></a> <a href="https://mastodon.social/tags/javaScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>javaScript</span></a> <a href="https://mastodon.social/tags/types" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>types</span></a> <a href="https://mastodon.social/tags/typing" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>typing</span></a> <a href="https://mastodon.social/tags/programming" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>programming</span></a> <a href="https://mastodon.social/tags/webDev" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>webDev</span></a> <a href="https://mastodon.social/tags/jsdoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>jsdoc</span></a> <a href="https://mastodon.social/tags/jsdocs" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>jsdocs</span></a></p>
Aral Balkan<p>If you use a parameter object in JavaScript, even if you specify its shape using JSDoc, you’ll only get errors if required properties are missing; not if there are extra properties provided.</p><p>e.g.,</p><p>```js<br>class A {<br> /**<br> @param {{<br> id:string<br> }} params<br> */<br> constructor (params) {<br> Object.assign(this, params)<br> }<br>}</p><p>// Error:<br>new A({})</p><p>// No error:<br>new A({id: 'x', foo:'bar'})<br>```</p><p>According to this thread, it’s a fact-of-life: </p><p><a href="https://stackoverflow.com/questions/49580725/is-it-possible-to-restrict-typescript-object-to-contain-only-properties-defined" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">stackoverflow.com/questions/49</span><span class="invisible">580725/is-it-possible-to-restrict-typescript-object-to-contain-only-properties-defined</span></a></p><p><a href="https://mastodon.ar.al/tags/JavaScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JavaScript</span></a> <a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a></p>
🧿🪬🍄🌈🎮💻🚲🥓🎃💀🏴🛻🇺🇸<p>&gt; JSR motivates best practices in code distribution—higher scores are awarded to packages that include comprehensive JSDoc documentation on each exported symbol</p><p><a href="https://deno.com/blog/jsr-is-not-another-package-manager" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">deno.com/blog/jsr-is-not-anoth</span><span class="invisible">er-package-manager</span></a></p><p><a href="https://mastodon.social/tags/jsr" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>jsr</span></a> <a href="https://mastodon.social/tags/webDev" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>webDev</span></a> <a href="https://mastodon.social/tags/javaScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>javaScript</span></a> <a href="https://mastodon.social/tags/nodejs" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>nodejs</span></a> <a href="https://mastodon.social/tags/typescript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>typescript</span></a> <a href="https://mastodon.social/tags/jsdoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>jsdoc</span></a> <a href="https://mastodon.social/tags/types" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>types</span></a> <a href="https://mastodon.social/tags/programming" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>programming</span></a> <a href="https://mastodon.social/tags/technology" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>technology</span></a></p>
Aral Balkan<p>Yeah, I have no idea how this is still an issue in JSDoc in 2023. It looks like the project is abandoned – which is a damn shame for those of us who want type safety without having to introduce a build step using TypeScript in our projects.</p><p><a href="https://github.com/jsdoc/jsdoc/issues/1349#issuecomment-1725400751" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/jsdoc/jsdoc/issues/</span><span class="invisible">1349#issuecomment-1725400751</span></a></p><p><a href="https://mastodon.ar.al/tags/web" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>web</span></a> <a href="https://mastodon.ar.al/tags/JS" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JS</span></a> <a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a> <a href="https://mastodon.ar.al/tags/typescript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>typescript</span></a> <a href="https://mastodon.ar.al/tags/microsoft" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>microsoft</span></a> <a href="https://mastodon.ar.al/tags/lsp" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>lsp</span></a></p>
Aral Balkan<p>If you’re using JSDoc to cast, say, a global object to a class, here’s how you do it (TL; DR: Use `typeof` – it wasn’t immediately clear to me).</p><p><a href="https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/66713#discussioncomment-7043990" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/DefinitelyTyped/Def</span><span class="invisible">initelyTyped/discussions/66713#discussioncomment-7043990</span></a></p><p><a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a> <a href="https://mastodon.ar.al/tags/JS" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JS</span></a> <a href="https://mastodon.ar.al/tags/web" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>web</span></a> <a href="https://mastodon.ar.al/tags/dev" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>dev</span></a></p>
Aral Balkan<p>This took me way too long to figure out…</p><p>If your <a href="https://mastodon.ar.al/tags/js" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>js</span></a> function takes a parameter object and uses spread syntax to collect arbitrary additional properties (rest) and you want to document it using <a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a>, the syntax is:</p><p>[p:string]:any</p><p>e.g.,</p><p>```js<br>/**<br> @param {{<br> state: import('./SetupState.script.js').default,<br> [p:string]:any<br> }} parameterObject<br> @returns {string|string[]} html<br>*/<br>export default ({state, ...props}) =&gt; html`…`<br>```</p><p>Solution by Alexander Lonberg <a href="https://stackoverflow.com/a/68567492" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">stackoverflow.com/a/68567492</span><span class="invisible"></span></a></p>
Aral Balkan<p>A little <a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a> tip:</p><p>If you need to use a type definition in an external file multiple times, you don’t have to keep writing `import(…).type` over and over. Just create a new type definition in your local file and use that.</p><p>e.g.,</p><p>```js<br>/** @typedef {import('./SetupState.js').SetupStateType} SetupStateType */</p><p>const state = {<br> domain: /** @type SetupStateType */ (new SetupState('Domain')),<br> server: /** @type SetupStateType */ (new SetupState('Server')),<br> …<br>}<br>```</p><p><a href="https://mastodon.ar.al/tags/js" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>js</span></a> <a href="https://mastodon.ar.al/tags/web" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>web</span></a> <a href="https://mastodon.ar.al/tags/dev" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>dev</span></a></p>
Simon MacDonald<p>🚫 TypeScript: YAGNI</p><p>TypeScript! What is it good for? I wouldn’t go as far as to say “absolutely nothing” like the song. I’m not trying to start a war here. It certainly is widespread, with JetBrains estimating it has nearly tripled in popularity over the past six years. However, we are scientists and using popularity as a reason for adopting a new tool is an excellent way to commit a logical fallacy.</p><p><a href="https://mastodon.online/tags/typescript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>typescript</span></a> <a href="https://mastodon.online/tags/javascript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>javascript</span></a> <a href="https://mastodon.online/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a> </p><p><a href="https://begin.com/blog/posts/2023-07-19-typescript-yagni" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">begin.com/blog/posts/2023-07-1</span><span class="invisible">9-typescript-yagni</span></a></p>
Aral Balkan<p>- <a href="https://mastodon.ar.al/tags/JavaScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JavaScript</span></a> is a wonderfully dynamic language and its dynamic features afford you a great deal of expressiveness.</p><p>- Strong typing is useful for catching errors before runtime.</p><p>These two statements don’t have to be mutually exclusive.</p><p>Instead of shackling yourself to <a href="https://mastodon.ar.al/tags/TypeScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>TypeScript</span></a>™ 2023™ Enterprise Edition™, you can use <a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a> to get the best of both worlds.</p><p>Here, for example, I’m mixing a property into Polka request handlers and annotating it. My intent is clear and the type checker’s happy.</p>
Aral Balkan<p>PS. Some <a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a> <a href="https://mastodon.ar.al/tags/tips" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>tips</span></a>:</p><p>You can refer to types in other modules &amp; annotate parameters inline.</p><p>```<br>async createOrUpdate (/** @type import('stripe').Stripe */ stripe) { … }<br>```</p><p>You can define custom types, use unions:</p><p>```<br>@typedef {State &amp; RegistrationFormProperties} RegistrationFormStateType<br>```</p><p>You can cast (note the parentheses):</p><p>```<br>state = /** @type RegistrationFormStateType */ (new RegistrationFormState())<br>```</p><p>For more advanced uses, see Closure Type System: <a href="https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/google/closure-comp</span><span class="invisible">iler/wiki/Types-in-the-Closure-Type-System</span></a></p>
Aral Balkan<p>Want strong typing without a build process?</p><p>(Hint: you don’t need to use TypeScript.)</p><p>1. Use a modern editor like Helix Editor or VSCodium that supports the TypeScript Language Server (LSP). </p><p>2. Add this line to the top of your JavaScript file (without the backticks, if you see any):</p><p>```<br>// @ts-check<br>```</p><p>3. Go read up on JSDoc ;)</p><p>¹ <a href="https://helix-editor.com" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">helix-editor.com</span><span class="invisible"></span></a><br>² <a href="https://jsdoc.app/about-getting-started.html" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">jsdoc.app/about-getting-starte</span><span class="invisible">d.html</span></a></p><p><a href="https://mastodon.ar.al/tags/javaScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>javaScript</span></a> <a href="https://mastodon.ar.al/tags/typeSafety" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>typeSafety</span></a> <a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a> <a href="https://mastodon.ar.al/tags/lsp" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>lsp</span></a> <a href="https://mastodon.ar.al/tags/HelixEditor" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>HelixEditor</span></a> <a href="https://mastodon.ar.al/tags/typeScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>typeScript</span></a> <a href="https://mastodon.ar.al/tags/web" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>web</span></a> <a href="https://mastodon.ar.al/tags/dev" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>dev</span></a></p>
Aral Balkan<p>`SystemError` typedef for Node.js (gist)</p><p><a href="https://codeberg.org/aral/gists/src/branch/main/SystemError.md" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/aral/gists/src/br</span><span class="invisible">anch/main/SystemError.md</span></a></p><p>Node.js doesn’t expose the `SystemError` class in any way. This JSDoc type definition works around this limitation.</p><p>__Update:__ Yeah, Node.js should _really_ just expose the `SystemError` class because this is ridiculous.</p><p><a href="https://mastodon.ar.al/tags/NodeJS" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>NodeJS</span></a> <a href="https://mastodon.ar.al/tags/codeberg" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>codeberg</span></a> <a href="https://mastodon.ar.al/tags/gist" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>gist</span></a> <a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a></p>