Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Typescript declared types #642

Closed
1 of 2 tasks
xxRockOnxx opened this issue Jun 15, 2023 · 5 comments
Closed
1 of 2 tasks

Wrong Typescript declared types #642

xxRockOnxx opened this issue Jun 15, 2023 · 5 comments

Comments

@xxRockOnxx
Copy link
Contributor

xxRockOnxx commented Jun 15, 2023

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[itemprop="image"]').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.

@Kikobeats
Copy link
Member

Kikobeats commented Jun 15, 2023

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

@xxRockOnxx
Copy link
Contributor Author

@Kikobeats what is the release cycle or when is the next version coming out?

@Kikobeats
Copy link
Member

as soon as PR is merged, a new version is released

@xxRockOnxx
Copy link
Contributor Author

it's been merged and it's still on 5.34.7

@Kikobeats
Copy link
Member

oh sorry; [email protected] released 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants