rbren / rss-parser

A lightweight RSS parser, for Node and the browser
MIT License
1.35k stars 209 forks source link

tsc fails with strict mode on #121

Open repentsinner opened 5 years ago

repentsinner commented 5 years ago

I've added rss-parser to a project that was using strict mode in tsconfig.json, and am getting failed builds:

node_modules/rss-parser/index.d.ts:1:25 - error TS7016: Could not find a declaration file for module 'xml2js'. '/Users/deg/Development/ts_rss_parser/node_modules/xml2js/lib/xml2js.js' implicitly has an 'any' type.
  Try `npm install @types/xml2js` if it exists or add a new declaration (.d.ts) file containing `declare module 'xml2js';`

I can either add @types/xml2js as a peer dependency or disable strict mode to get the project to build. I see that @types/xml2js is a devDependency in rss-parser, but I understand that npm doesn't recursively install dev dependencies.

I'm somewhat new to Typescript and npm dependency management behavior so I am not sure the best way to resolve this. Usually if something requires a peer dependency npm warns me. So far no other packages I'm using have triggered this compile error, but I can't figure out if/how they're configured differently w/r/t type definitions for their own dependencies.

I've got a minimal project to repro here: https://github.com/repentsinner/ts_rss_parser

Thanks for considering!

repentsinner commented 5 years ago

Did some more reading on this, and I don't think I'm any clearer on the correct way to handle it:

https://github.com/microsoft/types-publisher/issues/81

Maybe mark it as a peerDependency so that npm indicates that it needs to be installed (rather than failing at compile time), but don't move it directly to dependencies as that appears to cause collisions in the global space?

namoscato commented 4 years ago

Thoughts on just copying xml2js's Options interface into this project's type definition?