jshemas / openGraphScraper

Node.js scraper service for Open Graph Info and More!
MIT License
668 stars 105 forks source link

Problem with specifying the html option in TypeScript #187

Closed gladevise closed 1 year ago

gladevise commented 1 year ago

Description

When using TypeScript version 5.1.3, an error occurs while trying to parse an HTML string like ogs({html}) as shown in the HTML Example. The error message received is as follows:

Argument of type '{ html: string; }' is not assignable to parameter of type 'OpenGraphScraperOptions'.
  Property 'url' is missing in type '{ html: string; }' but required in type 'OpenGraphScraperOptions'.ts(2345)

However, an attempt to rectify this issue by providing both url and html results in a new error at runtime:

Must specify either `url` or `html`, not both

Steps to Reproduce

The error can be reproduced using the following code snippet:

import ogs from 'open-graph-scraper';
const { result } = await ogs({ html });

This code triggers the aforementioned error message:

Argument of type '{ html: string; }' is not assignable to parameter of type 'OpenGraphScraperOptions'.
  Property 'url' is missing in type '{ html: string; }' but required in type 'OpenGraphScraperOptions'.ts(2345)

Expected Behavior

No error should be thrown and the parsing should proceed as intended.

Actual Behavior

Instead of the expected behavior, the error stated above is thrown.

Additional Information

This issue is experienced while using the OpenGraphScraper library, version 6.1.0.

jshemas commented 1 year ago

Your change is live in open-graph-scraper@6.2.0