laurengarcia / url-metadata

NPM module: Request a url and scrape the metadata from its HTML using Node.js or the browser.
https://www.npmjs.com/package/url-metadata
MIT License
166 stars 43 forks source link

First parameter can't be null in typescript #81

Closed ajmas closed 6 months ago

ajmas commented 6 months ago

I just got the latest version of url-metadata and tried the following code

const response = new Response(html);
const metadata = await urlMetadata(null, {
  requestHeaders: {
    ...(this.requestHeaders || {}),
    'Accept-Language': locale,
  },
  parseResponseObject: response
});    

VSCode is telling me Argument of type 'null' is not assignable to parameter of type 'string'. For now I can work around this by using null as any, but it isn't ideal.

One way of addressing this is with:

declare function urlMetadata(
  url: string | null,
  options?: urlMetadata.Options,
): Promise<urlMetadata.Result>

The may be some way of indicating null is only permitted when parseResponseObject is provided, but I'd have to explore, since my TS knowledge doesn't go that deep.

laurengarcia commented 6 months ago

Thanks for catching that. Strangely my editor didn't say anything, nor did the Typescript/ Parcel compiler i added to /example-typescript dir either. Sorry for the oversight.

New version 3.5.6 has the bugfix. https://www.npmjs.com/package/url-metadata