Support typescript for this fantastic library
abdatta opened this issue Β· comments
Hi,
Thanks a lot for this fantastic library. My only request is can you support typescript for this? There exists a ts version here, but it is not in sync with the library here. So we often miss out on the new features. A built-in ts support will be perfect for this. If you need, I can also try and help for this. Hope you agree on getting this done. π
As far as I understand, all that would be needed would be generating typedoc, correct?
If it doesn't mean beaking js compatability, I see no reason why not
Hey sorry for the late reply. I'll check the types and let you know by tomorrow. Thanks for following up on my request.
happy to!
Hey, again sorry for late. Yes, I checked out the types, and if I clone this as a repo and directly refer it in my projects, the types are detected well. However, when I install it as a library, it doesn't seem to support the types. I installed using
npm i https://github.com/filipedeschamps/rss-feed-emitter.git#types
to make sure I install the right branch, however when I write a simple code like this:
import RssFeedEmitter from 'rss-feed-emitter';
const feeder = new RssFeedEmitter();
I get any
as the type for feeder, whereas it should be of the type RssFeedEmitter
(as I get when I clone the repo instead)
I'm not sure if I'm doing it wrong, or if it'll get auto fixed when it is published on npm and I install it from there. Please let me know if I can help with anything else. Will make sure not to be late next time π
yeah, i guess i'm unsure as to the process for npm to pick up types from an installed package. I do wonder if the install is ignoring that bit of the package.json?
I don't see a FeedEmitter.d.ts
file for the FeedEmitter type. Is there a reason for leaving that out?
I have one in there...
I don't see one on Github. All the others are present, only FeedEmitter.d.ts
is missing.
Anyway I have fixed this on my local using help from here: https://voxpelli.com/2019/10/use-type-script-3-7-to-generate/
Created a tsconfig.declaration.json
file here:
{
"inlcude": [
"src/**/*.js"
],
"exclude": [
"test/**/*.js"
],
"compilerOptions": {
"outDir": "./types",
"declaration": true,
"noEmit": false,
"allowJs": true,
"emitDeclarationOnly": true
}
}
And in src/FeedEmitter.js
replaced this
const EventEmitter = require('events');
with this
const EventEmitter = require('events').EventEmitter;
by following this: puppeteer/puppeteer#5168
and then run npx tsc -p tsconfig.declaration.json
And the types work perfectly now :D
i'll give it a shot and add it in. i'm unsure why the require change is needed π€
Yes, the require change is the only thing that's concerning me. Test it out once and see if everything works as usual. Also, might need to check that this doesn't break any backwards compatibility (unless you're planning a major version jump with this).
tests run as they did. it doesn't break anything in our integration suite.
it still errors out for me π€
What's the error?
error TS5055: Cannot write file 'rss-feed-emitter/types/coverage/lcov-report/block-navigation.d.ts' because it would overwrite input file.
error TS5055: Cannot write file 'rss-feed-emitter/types/coverage/lcov-report/prettify.d.ts' because it would overwrite input file.
error TS5055: Cannot write file 'rss-feed-emitter/types/coverage/lcov-report/sorter.d.ts' because it would overwrite input file.
error TS5055: Cannot write file 'rss-feed-emitter/types/dist/rss-feed-emitter.d.ts' because it would overwrite input file.
error TS5055: Cannot write file 'rss-feed-emitter/types/dist/rss-feed-error.d.ts' because it would overwrite input file.
error TS5055: Cannot write file 'rss-feed-emitter/types/src/Feed.d.ts' because it would overwrite input file.
error TS5055: Cannot write file 'rss-feed-emitter/types/src/FeedEmitter.d.ts' because it would overwrite input file.
error TS5055: Cannot write file 'rss-feed-emitter/types/src/FeedError.d.ts' because it would overwrite input file.
error TS5055: Cannot write file 'rss-feed-emitter/types/src/FeedItem.d.ts' because it would overwrite input file.
error TS5055: Cannot write file 'rss-feed-emitter/types/src/FeedManager.d.ts' because it would overwrite input file.
Ahh.... remove the existing types dir first
Yeah, i did that and it gave the same thing.
I added an exclude for "types/**/*.*"
and it passes
seems like both branches are having issues with that tsconfig.json on the build
π This issue has been resolved in version 3.2.0 π
The release is available on:
Your semantic-release bot π¦π