#How do I use jsdoc for kubejs events in functions?

25 messages · Page 1 of 1 (latest)

upper reef
#

I want intellisense on functions that have an event parameter. I've been doing this for now (seems like ProbeJS suggests this?)

/** @param {import("dev.latvian.mods.kubejs.server.tag.TagKubeEvent").$TagKubeEvent$$Original} event */
function biomeTags_BountifulFares(event) {
    // code here
}
warped coveBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

wide locust
#

This is exactly how.

Annoyingly ProbeJS switched to dumping classes with modules instead of every class being in global scope.
Has benefits (not polluted global scope, better performance), but also drawbacks:

  • Explicit types have to be imported
  • So many goddamn $ sigils
  • Dumped literal strings are unusable for type checking (TS still does type checking under the hood, it just doesn't display type errors if type checking is disabled, but it can mess up inference in certain cases)

So you can either:

  1. Use a dynamic import type (like you did),
  2. Use an @import JSDoc tag:
/** @import {$TagKubeEvent} from "dev.latvian.mods.kubejs.server.tag.TagKubeEvent" */

/** @param {$TagKubeEvent} event */
function biomeTags_BountifulFares(event) {
    // code here
}
#

(I have no idea, why ProbeJS even dumps $$Original types, they are the same as the type with no sigils)

upper reef
wide locust
#

Nope, you gotta import needed types one by one.

wide locust
#

If you do an import like this:

/** @import {$TagKubeEvent} from "dev.latvian.mods.kubejs.server.tag.TagKubeEvent" */

or

/** @typedef {import("dev.latvian.mods.kubejs.server.tag.TagKubeEvent").$TagKubeEvent} $TagKubeEvent */

the type will be exposed to global scope, therefore accessible in all scripts of a kind

upper reef
#

ahh okay, thanks!

#

that works :D

#

one last thing, can i jsdoc the tag event type? in this case, the item tag event or block tag event

wide locust
#

What do you mean?

#

You mean the type of event in let's say,

ServerEvents.tags("item", event => {
  // ...
})

?

#

Pro tip: You can ctrl + click various identifiers to look where they come from

#

This will take you to a .d.ts file where the names are declared

#

Expert Java developer vs TypeScript moment

#

(this could have been an interface)

upper reef
upper reef
#

i dont really understand how probejs works with vscode :p

wide locust
#

Simple - import the $TagEventProbe type.
It has type parameters you have to specify later in angled brackets:

/** @import {$TagEventProbe} from "moe.wolfgirl.probejs.generated.TagEventProbe" */
/** @param {$TagEventProbe<Special.ItemTag, Special.Item>} event  */
function itemTagThing(event) {

}
wide locust
upper reef
#

ah alright

#

thanks!