Fork me on GitHub
#shadow-cljs
<
2024-03-21
>
cap10morgan15:03:41

Is :jsdoc metadata no longer supported? I can't seem to get it to actually output the JSDoc comments in the compiled javascript. This is w/ simple optimizations for a node library.

cap10morgan15:03:26

hmm... doesn't work for me. I'm trying to add a @param {string} jws jsdoc string and I can't find it in the output JS

thheller15:03:20

where did you use it? it only works on def and defn? or possibly bindngs, I'm not actually sure

cap10morgan15:03:45

I've tried this:

(defn ^{:export true, :jsdoc ["@param {string} jws"]} verify-jws
  [jws]
  (-> jws fc/verify-jws clj->js))

cap10morgan16:03:03

and this (following your example above):

(defn ^:export verify-jws {:jsdoc ["@param {string} jws"]}
  [jws]
  (-> jws fc/verify-jws clj->js))

thheller16:03:05

that looks fine, although I'm unsure what that tag is for? after optimizations that tag will be gone?

cap10morgan16:03:44

for better typescript type declarations

cap10morgan16:03:02

but if that's the case, that would explain why I'm not seeing it 🙂

thheller16:03:21

how or where would typescript type declarations come from?

cap10morgan16:03:56

the typescript compiler can generate them from js sources and can use jsdoc annotations for better type info when they're available

thheller16:03:12

/**
 * @param {string} jws
 */
demo.browser.verify_jws = (function demo$browser$verify_jws(jws){
return cljs.core.clj__GT_js(jws);
});

thheller16:03:16

shows up just fine

thheller16:03:48

well if its generating them from release compiled sources then it won't have much luck

thheller16:03:08

closure removes @param annotations as part of optimizations, they it assumes its for its guidance

cap10morgan16:03:46

we're explicitly using simple optimizations for other reasons

thheller16:03:10

its still optimizations, so that changes nothing

thheller16:03:41

there might be an option to tell it to keep them, but I can't remember

thheller16:03:16

I'd say there is close to zero chance for type annotations to remain in a shape where typescript can find them

cap10morgan16:03:23

it is running shadow-cljs release so that must be why

thheller16:03:29

since even ^:export it won't recognize

cap10morgan16:03:11

ok, I'll give up for now then. just wanted to make sure I wasn't something simple to enable better types

thheller16:03:31

I have never done anything with typescript, so I don't know how types would be extracted

thheller16:03:07

it should be fairly easy to generate .d.ts files using a build hook though, since that can see whats exported and what metadata those vars have

cap10morgan16:03:29

oh, that could be interesting

cap10morgan16:03:48

probably more work than it's worth right now, but good to know