Wrong Typescript declared types
xxRockOnxx opened this issue · comments
Prerequisites
- I'm using the last version.
- My node version is the same as declared as
package.json
.
Subject of the issue
The Typescript types are not correct.
Package like metascraper-image exports a function that returns an object.
i.e
module.exports = () => ({
image: [
toImage($ => $('meta[property="og:image:secure_url"]').attr('content')),
toImage($ => $('meta[property="og:image:url"]').attr('content')),
toImage($ => $('meta[property="og:image"]').attr('content')),
toImage($ => $('meta[name="twitter:image:src"]').attr('content')),
toImage($ => $('meta[property="twitter:image:src"]').attr('content')),
toImage($ => $('meta[name="twitter:image"]').attr('content')),
toImage($ => $('meta[property="twitter:image"]').attr('content')),
toImage($ => $('meta[]').attr('content')),
toImage($jsonld('image.0.url')),
toImage($jsonld('image.url')),
toImage($jsonld('image.url')),
toImage($jsonld('image')),
toImage($ => $filter($, $('article img[src]'), getSrc)),
toImage($ => $filter($, $('#content img[src]'), getSrc)),
toImage($ => $('img[alt*="author" i]').attr('src')),
toImage($ => $('img[src]:not([aria-hidden="true"])').attr('src'))
]
})
However in the declaration file, metascraper-*
packages exports a function that returns a function that returns an object which is not true.
i.e
type Rule = () => RuleSet;
declare module 'metascraper-*' {
export default function rules(): import('metascraper').Rule;
}
For more clarity, the expanded equivalent is:
export default function rules(): () => RuleSet
I believe it should return RuleSet
directly instead.
Next, the "constructor" function accepts wrong types.
It should accept RuleSet
and not Rules
.
If it were to accept Rules
, the "constructor" should look like:
const metascraper = Metascraper([
MetascraperImage
])
instead of
const metascraper = Metascraper([
MetascraperImage()
])
htmlDom
from CheckOptions
interface should also be
interface CheckOptions {
htmlDom: import('cheerio').CheerioAPI;
url: string
}
instead of
interface CheckOptions {
htmlDom: typeof import('cheerio');
url: string
}
Otherwise it causes the error "This expression is not callable."
I can submit a PR but I'm not sure yet if this is intentional or if I'm missing something.
Hello, they're definitely outdated; Can you send a PR? 🙏
Also, I think it's missing rules set can contain a test
function:
https://github.com/microlinkhq/metascraper/blob/v5.34.7/packages/metascraper-youtube/index.js#L47
@Kikobeats what is the release cycle or when is the next version coming out?
as soon as PR is merged, a new version is released
it's been merged and it's still on 5.34.7
oh sorry; metascraper@5.34.8
released 🙂