filipedeschamps / rss-feed-emitter

Super RSS News Feed aggregator written in Node.js and ES6

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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. πŸ˜„

commented

As far as I understand, all that would be needed would be generating typedoc, correct?

commented

If it doesn't mean beaking js compatability, I see no reason why not

commented

@abdatta could you check out and test out our types on #193? If these are adequate, I'll add a build step in our CI so they're always generated before it's shipped off to npm

Hey sorry for the late reply. I'll check the types and let you know by tomorrow. Thanks for following up on my request.

commented

happy to!

commented

@abdatta any luck?

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 πŸ˜…

commented

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?

commented

I have one in there...

I don't see one on Github. All the others are present, only FeedEmitter.d.ts is missing.
image

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

commented

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).

commented

tests run as they did. it doesn't break anything in our integration suite.

commented

it still errors out for me πŸ€”

What's the error?

commented
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

commented

Yeah, i did that and it gave the same thing.

commented

I added an exclude for "types/**/*.*" and it passes

commented

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 πŸ“¦πŸš€