#How do I use jsdoc for kubejs events in functions?
25 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
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:
- Use a dynamic import type (like you did),
- Use an
@importJSDoc 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)
hmm.. could i have import for all files/functions maybe?
Nope, you gotta import needed types one by one.
Or I misunderstood you
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
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
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)
yeah, like how do i jsdoc the $TagEventProb<T, I> for different tag types (items, blocks, worldgen/biome, etc)
yeah i just have no idea how to translate the typings to js doc or whatever
i dont really understand how probejs works with vscode :p
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) {
}
Also, you are actually using TypeScript, not strictly "VS Code".
All of JSDoc that TypeScript supports and understands as TS syntax:
https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html
What JSDoc does TypeScript-powered JavaScript support?