It's incredibly validating to me to hear everyone questioning #Typescript.
I've been hating it's guts for like 4 years now, saying that people should just use #JSdoc
Glad y'all are finally getting off the hype-train!
#webdev #js #javascript #jsdoc #typescript
๐ Loved this new #Fireship video about #TypeScript
I have been advocating for #JSDoc instead of going full TS for years.
#fireship #typescript #jsdoc #Frontend #JavaScript #webdevelopment
This took me way too long to figure outโฆ
If your #js function takes a parameter object and uses spread syntax to collect arbitrary additional properties (rest) and you want to document it using #JSDoc, the syntax is:
[p:string]:any
e.g.,
```js
/**
@param {{
state: import('./SetupState.script.js').default,
[p:string]:any
}} parameterObject
@returns {string|string[]} html
*/
export default ({state, ...props}) => html`โฆ`
```
Solution by Alexander Lonberg https://stackoverflow.com/a/68567492
A little #JSDoc tip:
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.
e.g.,
```js
/** @typedef {import('./SetupState.js').SetupStateType} SetupStateType */
const state = {
domain: /** @type SetupStateType */ (new SetupState('Domain')),
server: /** @type SetupStateType */ (new SetupState('Server')),
โฆ
}
```
@grooovinger @castastrophe @kizu @rach
Since generics were not working very well in #JSDoc 6 months ago, I still have this lingering feeling that tossing #TypeScript right away in favor of JSDoc is going to hurt some projects. If the situation with "templates"/generics has been resolved since then, then I would be able to seriously suggest moving to such opt-in commenting.
I love it when a library lets you choose between #JavaScript and #Typescript in the code examples, but I wish that they would include the #JSDoc types in the #JS version since they don't hurt anything and they are still helpful when you're using #VSCode #WebDev
#webdev #vscode #js #jsdoc #typescript #javascript
- #JavaScript is a wonderfully dynamic language and its dynamic features afford you a great deal of expressiveness.
- Strong typing is useful for catching errors before runtime.
These two statements donโt have to be mutually exclusive.
Instead of shackling yourself to #TypeScriptโข 2023โข Enterprise Editionโข, you can use #JSDoc to get the best of both worlds.
Here, for example, Iโm mixing in a property into Polka request handlers and documenting it. Intent is clear and type checker is happy.
#javascript #typescript #jsdoc
Interesting things about what you can do with #JSDoc that #TypeScript alone doesn't let you do. https://syntax.fm/show/624/is-jsdoc-better-than-typescript
You can refer to types in other modules.
```
async createOrUpdate (/** @type import('stripe').Stripe */ stripe) {
// โฆ
}
```
You can cast (note the parenthesis surrounding the cast):
```
state = /** @type RegistrationFormStateType */ (new RegistrationFormState())
```
You can annotate parameters inline:
```
function formattedMinimumPriceForCurrency (/** @type string */ currency) {
// โฆ
}
```
For more advanced uses, see Closure Type System: https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System
Want strong typing without a build process?
(Hint: you donโt need to use TypeScript.)
1. Use a modern editor like Helix Editor or VSCodium that supports the TypeScript Language Server (LSP).
2. Add this to the top of your JavaScript file (without the backticks):
```
// @ts-check
```
3. Go read up on JSDoc ;)
ยน https://helix-editor.com
ยฒ https://jsdoc.app/about-getting-started.html
#javaScript #typeSafety #JSDoc #lsp #HelixEditor #typeScript #web #dev
#javascript #typesafety #jsdoc #lsp #HelixEditor #typescript #web #dev
The discussion #TypeScript vs. #JSDoc with #SvelteKit, triggered by a sound byte of @rich_harris, always derails into a type safety or not train wreck.
Everyone wants type safety for anything deployed in prod (hopefully). But there are different ways to get there.
JSDoc is just an alternative way of using TypeScript. But itโs still TypeScript.
https://reddit.com/r/sveltejs/comments/12vvsjp/sveltekit_with_jsdoc_or_with_typescript/
SystemError typedef for Node.js (gist)
https://codeberg.org/aral/gists/src/branch/main/SystemError.md
Node.js doesnโt expose the SystemError class in any way. This JSDoc type definition works around this limitation.
#nodejs #codeberg #gist #jsdoc
@schizanon @thudfactor Last Friday's This week in #Svelte looked at #JSDoc vs. #TypeScript:
https://youtu.be/sRhZQ-2VxVU?t=2420
Starts at 40:20.
#JSDoc's module support is not to my liking.
And by not to my liking I mean hot garbage.
@thilo I've not used external definitions much personally, except when I need to import a type from a library. @enhance_dev does a great job of using #JSDoc for types in their docs. @see: https://enhance.dev/docs/learn/practices/types
@schizanon @thudfactor I am in the process of converting my #SvelteKit site from #Typescript to #JSDoc TS.
Do you have any recommendations on how to complement JSDoc comments with .d.ts files?
I found that type definitions in .d.ts files and then importing them into JSDoc comments makes things easier.
But Iโm having a hard time finding code bases that use JSDoc to learn from.
so I built a plugin for #TypeDoc that contains some functionality like โautomatic @inheritDocโ, where if you neglect to document T, and T overrides/implements U, the result will copy the documentation from U into T when rendered. would anyone find this useful? if so I may release it standalone. #TypeScript #JSDoc
Can't believe I'm about to share #typescript content, but version 5.0 adds support for @satisfies and @overload to #JSDoc and that's p cool ๐
#Overload let's you type functions that can take different arguments which seems bad but w/e https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#overload-support-in-jsdoc
#Satisfies is some TS bs bullshit I haven't figured out yet but which is probably useful sometimes https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#satisfies-support-in-jsdoc
I just like to see parity with JSDocs and TS Syntax!
#satisfies #overload #jsdoc #typescript
is there some way to use @typedef to import a type but not create a new one and/or not export it?
I think this is my main pain-point with #jsdoc for #typescript. if the thing youโre importing has type args, you seem to have to duplicate them or have โimport(..).Fooโ everywhere. am I missing something? can I use triple-slash directives somehow?
"I am using the fetch API to fetch some #JSON, how can add #types to the response using #Typescript to check types in #JavaScript using #JSDoc annotations?" #chatGPT #ai #programming
#programming #ai #chatgpt #jsdoc #javascript #typescript #types #json