-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement .d.ts
generation from jsdoc comments
#662
Conversation
Just added generation of |
Pull Request Test Coverage Report for Build 9501516245Details
💛 - Coveralls |
Removing Can you take a look at what the generated api docs look like for the changes you've made and maybe post a screenshot? A compromise might be to use e.g. You could also experiment with using I'll try to take a closer look, but maybe we could get someone with more typescript experience to comment since I haven't used it much if at all. |
Sure, this is what the Documentation looks like with If you have the time you can also clone this fork and build the docs locally to see how it looks for yourself to get the full picture. Other than that it seems that the type hints that jsdoc should give you don't even work with the current implementation as in the It seems to me that I don't really understand the part with the namespacing you mentioned. Yes a user can do I also experimented a bit with I'd be happy to implement the compromise you mentioned for the rest of the codebase: changing all references to |
It is more of an optics thing. Technically of course it works, but this isn't how I intended it to be and I don't want that pattern to establish. I read a little bit about types and saw there is something like |
Just to clarify, this the current changes of my fork look like from a library consumer perspective: Usage in typescript (js would be identical in this example I believe): // import still works like it used to
import ICAL from "ical.js-test";
const { Component } = ICAL;
const data = "...some ical data";
const jCalData = ICAL.parse(data);
// the type of this comp is still ICAL.Component
const comp = new ICAL.Component(jCalData, null);
// even the type of comp2 is ICAL.Component
const comp2 = new Component(jCalData, null);
const events = comp.getAllSubcomponents("vevent");
for (const event of events) {
// event also is of type ICAL.Component
event;
} So for the library consumer this still looks correct right? The type shows up correctly as I don't think the |
Apologies I haven't gotten back, for some reason I had wrongly assumed I was waiting on a reply from you and skipped over this PR when going through the other issues. The example you show is as expected. Here is my thinking:
Therefore, if the generated documentation could always use e.g. https://kewisch.github.io/ical.js/api/ICAL.Event.html has a https://kewisch.github.io/ical.js/api/ICAL.Component.html has ICAL.Component in the header, the parent parameter is also ICAL.Component. This is good. The fact that it says Sorry for making this more complicated than it seems. If you want to find me on Matrix to chat, I am |
@jannikac Following our discussion on Matrix, I've pushed two commits that should make things work as well as they probably can. I see the dilemma that vscode won't complete the code, and don't see a way to fix this with typescript. Instead, the new jsdoc plugin will change the param names to include the module for the generated docs, while allowing to remove the alias and prefix in the params so typescript completion works. the To get this to work for me I had to make the following additional changes you should look into:
diff --git a/package.json b/package.json
index 23aafc7..ddd973c 100644
--- a/package.json
+++ b/package.json
@@ -63,7 +63,10 @@
"ghpages": "npm run jsdoc && npm run validator"
},
"exports": {
- "import": "./dist/ical.min.js",
+ "import": {
+ "default": "./dist/ical.min.js",
+ "types": "./dist/types/module.d.ts"
+ },
"require": "./dist/ical.es5.min.cjs"
},
"files": [
diff --git a/tsconfig.json b/tsconfig.json
index b30608e..f41ddfc 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,5 +1,8 @@
{
"compilerOptions": {
+ "target": "es2021",
+ "module": "nodenext",
+ "moduleResolution": "nodenext",
// Tells TypeScript to read JS files, as
// normally they are ignored as source files
"allowJs": true,
@@ -11,5 +14,6 @@
// "Go to Definition" in VSCode
"declarationMap": true,
"declarationDir": "dist/types"
- }
-}
\ No newline at end of file
+ },
+ "include": ["lib/ical/**/*.js"]
+} I didn't actually commit this since I only have a shallow understanding of what I did there, I'd appreciate if you could take a look if this is necessary and complete any other missing pieces such as potential types for the |
Hey just wanted to post a update on the state of types and a comment for my commits made recently: Current state of type generationWhat works
What doesnt work
I'd say 80-90% of types are generated correctly and avalible to library consumers but the typedef issue still stands. ill try to look into it more but would apreciate some input if someone is reading this. I'm not sure if @kewisch would want to merge an incomplete implementation of types generation because that would probrably cause more issues to be opened like "Recur.freq doesnt return a type that can be resolved". Comments on the recently made commitsfb1473f
b098f05
f08fd34
b525f35
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there, just a few minor changes. Thank you for putting so much effort into this, I'm looking forward to the merge!
…ld and add types to package.json
…defs for the `jsdoc-ical.cjs` plugin
…to `types.d.js` for consistency
…lect symbols, once to generate docs
This is a draft. This PR exists to discuss the automatic generation of a
.d.ts
file for typescript consumers of this library. The.d.ts
file should be generated from the existing jsdoc comments. Some changes have to be made to the jsdoc comments so that the generated.d.ts
file has the correct typings (#367 (comment)).The following snippet was used to test the correctness of the types:
I've just tried to fix the
lib/ical/component.js
file so that the typing work correctly. I will add the others if this is confirmed to be the way to go. I got it to work by removing the@alias ICAL.Component
comment and removing theICAL.
specifier for the Component class. This can be observed in commit #822b5c0.I've also generated the documentation with
npm run jsdoc
and ran the tests which worked. The snippet above seems to work with this approach aswell (event
has the correct methods attached). So far this looks good to me however there could be other reasons whyICAL.Component
is used instead of justComponent
. Perhaps @kewisch could supply some info on that or if the removal ofICAL.
is problematic otherwise. If there are no objections I'll removeICAL.
from the other classes aswell and add thed.ts
generation into the build pipeline.