ical.js icon indicating copy to clipboard operation
ical.js copied to clipboard

Generate TypeScript ical.d.ts from jsdoc and include in releases

Open knut-erik opened this issue 6 years ago ā€¢ 34 comments

Anybody which know if there exists a ical.d.ts file for TypeScript @types module?

knut-erik avatar Sep 20 '18 15:09 knut-erik

I'm mostly worried about keeping this file up to date. @glixlur Did you write that by hand, or was it automatically generated?

kewisch avatar Nov 09 '18 09:11 kewisch

Cool - tx @glixlur

knut-erik avatar Nov 09 '18 17:11 knut-erik

@kewisch Do you have any work around to import ical.js into angular 6 project ? If not @glixlur it will be really cool if you could work it out with @kewisch ?

i am looking forward to see if you can pull it of, would be really nice to have this lib Ts compliant :)

sebius8780 avatar Dec 07 '18 11:12 sebius8780

hi, how can I use @glixlur types?

ALGDB avatar Dec 10 '18 15:12 ALGDB

Hi Just to understand.

in:

new Component(jCal, parent)

parent is optional or mandatory as stated in the docs?

because, as far as I can see it seems optional component.js

function Component(jCal, parent) { 
if (typeof(jCal) === 'string') {
 // jCal spec (name, properties, components)
 jCal = [jCal, [], []];
}
 // mostly for legacy reasons.
 this.jCal = jCal; 
this.parent = parent || null;
  }

ALGDB avatar Dec 11 '18 10:12 ALGDB

I made it work using undefined, you should be able to make it right within the d.ts file though.

sebius8780 avatar Dec 11 '18 10:12 sebius8780

I have a manually created (though incomplete) typing file I created. I use it extensively in and add parts as I get to them https://github.com/etesync/etesync-web The actual file: https://github.com/etesync/etesync-web/blob/master/src/types/ical.js.d.ts (I updated it a bit more since, will push those local changes soon I hope). Also, I created it manually. If there's a way to create it automatically (@proteria ?) that would be much better (as long as it respects optional parameters). :P

I can take a look into making it more complete and submit a patch if there's interest. @kewisch ?

Otherwise it can go to https://github.com/DefinitelyTyped/DefinitelyTyped but then you'd have even less control when it comes to keeping it up to date.

tasn avatar Jul 25 '19 07:07 tasn

I'd prefer something that is auto-generated, I don't want to be updating this file manually or requiring it for people making pull requests.

kewisch avatar Jul 25 '19 07:07 kewisch

Obviously preferable, though how often does the API actually change? At the moment people (like myself and @proteria) end up manually implementing it for ourselves, and who knows how many others like us are there. I think having a version (@proteria's?) that covers what there's there now and worst case have her lag behind a bit in the future or until an automatic generator is implemented may be better, no?

I'm content with my hand-rolled types for myself, so no rush on my side. I'm just giving feedback based on my usage of this library and others with missing or incomplete typings.

tasn avatar Jul 25 '19 07:07 tasn

up! I'm just writing a new project and I don't really like to take half a day fixing other types or writing it myself.

HugoGresse avatar Dec 23 '19 14:12 HugoGresse

@HugoGresse, it's far from complete, but take a look at: https://github.com/etesync/ios/blob/master/src/types/ical.js.d.ts

tasn avatar Dec 23 '19 14:12 tasn

thanks @tasn šŸ‘ Small note: add TSlint to your project, the main error is public static that replace static public

HugoGresse avatar Dec 23 '19 14:12 HugoGresse

@HugoGresse, tslint is deprecated, I use eslint with the typescript plugin (you can see the config in the root of the repo). What rule was it that was triggered for you? I'll add it to my config.

tasn avatar Dec 23 '19 14:12 tasn

arf, Firebase functions still use it :( this is the default firebase functions config for tslint: https://github.com/HugoGresse/open-feedback/blob/master/functions/tslint.json

HugoGresse avatar Dec 23 '19 14:12 HugoGresse

No idea then, not important enough to try to figure out the tslint rule. Thanks though.

tasn avatar Dec 23 '19 14:12 tasn

Are there any official typings available yet for ical.js?

amadeus-torwell avatar Mar 02 '20 07:03 amadeus-torwell

Up

Catlike14 avatar Nov 22 '21 09:11 Catlike14

Would you mind if I use your definitions in the meantime? @tasn

zomars avatar Nov 25 '21 18:11 zomars

Careful using that .d.ts file - the top of it states it is GPL3 meaning your entire codebase becomes GPL if you include it.

MattRiddell avatar Feb 25 '22 12:02 MattRiddell

@tasn any chance you'd be able to make a copy with the same license as this codebase?

MattRiddell avatar Feb 25 '22 12:02 MattRiddell

@zomars, sorry, sure thing!

@MattRiddell, sure thing, sorry about that, will do now.

tasn avatar Feb 25 '22 13:02 tasn

Done. We actually have two versions, not sure which is newer/better:

https://github.com/etesync/ios/blob/master/src/types/ical.js.d.ts https://github.com/etesync/etesync-web/blob/master/src/types/ical.js.d.ts

Relicensed both.

tasn avatar Feb 25 '22 13:02 tasn

@tasn awesome, thanks man!

MattRiddell avatar Feb 25 '22 13:02 MattRiddell

In light of new recent comments I took a quick look on the net, apparently tsc can create the declaration file based on jsdoc? ical.js uses fairly comprehensive jsdoc, so maybe auto generated types are not too far off.

If someone wants to see how well these compare to the manual version that would be pretty cool. Note for the record I have a draft pr for es6 modules support which changes some doc patterns, so maybe base any changes off of that.

kewisch avatar Feb 25 '22 23:02 kewisch

I had a look at auto generating typescript definitions from jsdocs.

Overall it worked well, but typescript stumbled on the ICAL namespace. I could not find @namespace or @alias in the typescript jsdoc docs, which might be the problem, but I'm not enough of an expert of jsdoc to know for sure. This meant that any function that returns a class from said namespace would not resolve (for example: Event.startDate would have no type).

Side note on es modules, I added a re-export of items from the default namespace as named exports. This means you can import classes directly, and get the advantage of tree-shaking like:

import { parse, Event } from 'ical.js';

Here if a diff of what I did: https://github.com/kewisch/ical.js/compare/es6...joelshepherd:es6

joelshepherd avatar Apr 27 '22 12:04 joelshepherd

@kewisch https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html, could set up either CI or a commit hook to update the types automatically.

ryzokuken avatar Apr 10 '23 18:04 ryzokuken

Related: I forked the project and ported the entire project to TypeScript. Iā€™m open to merging this to upstream if anyone is interested.

alex-kinokon avatar Apr 13 '23 22:04 alex-kinokon

I'll happily migrate if we get passing tests and full coverage @alex-kinokon šŸ™šŸ½

zomars avatar Apr 14 '23 21:04 zomars

slightly urgent considering the entire ecosystem is going to ts. Can't run this at all in post 0.71 react-native projects

frozencap avatar Jun 24 '23 13:06 frozencap

slightly urgent considering the entire ecosystem is going to ts. Can't run this at all in post 0.71 react-native projects

Iā€™m fairly certain you can just put declare module "ical.js" in a .d.ts file somewhere and it would work.

alex-kinokon avatar Jun 24 '23 22:06 alex-kinokon