aral,
@aral@mastodon.ar.al avatar

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 line to the top of your JavaScript file (without the backticks, if you see any):

// @ts-check  
  1. Go read up on JSDoc ;)

¹ https://helix-editor.com
² https://jsdoc.app/about-getting-started.html

Shini92,
@Shini92@mas.to avatar

@aral // @ts-check is really welcome and needed for files like eslint config or prettier config where you do not have other options like TS

So for example in #faker we use it like this https://github.com/faker-js/faker/blob/ede6ffac383a853c12b7a47cebbb031ba80627aa/.eslintrc.js#LL1C1-L1C1 together with https://github.com/Shinigami92/eslint-define-config

aral,
@aral@mastodon.ar.al avatar

@Shini92 Nice. One very similar use case for me is database schemas for JavaScript Database (JSDB)¹, which is part of Kitten² :)

https://codeberg.org/domain/app/src/branch/main/app_modules/database/database.js

¹ https://codeberg.org/small-tech/jsdb
² https://codeberg.org/kitten/app

#jsdb #kitten #SmallWeb #database #web #dev

lea,

@aral the helix editor looks like a nice editor to try, thank you 💜

aral,
@aral@mastodon.ar.al avatar

@lea You’re very welcome; hope you enjoy it :) 💕

aral, (edited )
@aral@mastodon.ar.al avatar

PS. Some #JSDoc #tips:

You can refer to types in other modules & annotate parameters inline.

async createOrUpdate (/** @type import('stripe').Stripe */ stripe) { … }  

You can define custom types, use unions:

@typedef {State & RegistrationFormProperties} RegistrationFormStateType  

You can cast (note the parentheses):

state = /** @type RegistrationFormStateType */ (new RegistrationFormState())  

For more advanced uses, see Closure Type System: https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System

aral,
@aral@mastodon.ar.al avatar

(All examples taken from Domain – https://codeberg.org/domain/app – the work-in-progress free and open platform for Small Web hosts.)

#SmallWeb #Domain #Kitten #decentralisation #web #dev

orta,

@aral ( FWIW, I'd recommend recommending the TypeScript JSDoc reference (as that is what is powering all the JSDoc editor tooling! ) https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html )

aral,
@aral@mastodon.ar.al avatar

@orta Thanks :)

simulo,
@simulo@hci.social avatar

@aral I love JS Doc (also for the small doc comments that the editor will display when using it); What I find difficult is that interfaces/implements could be very useful, but importing these from another file is …awkward? Does not work? Is undocumented? …certainly a mess.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programming
  • DreamBathrooms
  • everett
  • InstantRegret
  • magazineikmin
  • thenastyranch
  • rosin
  • GTA5RPClips
  • Durango
  • Youngstown
  • slotface
  • khanakhh
  • kavyap
  • ngwrru68w68
  • tacticalgear
  • JUstTest
  • osvaldo12
  • tester
  • cubers
  • cisconetworking
  • mdbf
  • ethstaker
  • modclub
  • Leos
  • anitta
  • normalnudes
  • megavids
  • provamag3
  • lostlight
  • All magazines