extractus / oembed-extractor

Extract oEmbed data from given webpage
https://extractor-demos.pages.dev/oembed-extractor
MIT License
108 stars 43 forks source link

Issues with the Typescript types of this package #175

Closed Svish closed 7 months ago

Svish commented 1 year ago

The type returned by extract seems to be thought as a discriminated union, but the way it's written, it doesn't actually work as one.

This means it for example is not possible to access the html property of a response with type: 'video', even after checking that the type is indeed 'video'.

import { extract } from '@extractus/oembed-extractor'

const data = await extract('https://vimeo.com/6428069');

switch(data.type) {
    case 'video':
        console.log(data.html)
        break;
}

Exampe on TS Playground

I also notice there's a lot of optional fields on all the types in this project. Would be good if they could be non-optional, so we don't have to constantly check whether something is there or not.

ndaidong commented 1 year ago

@Svish thank you for you notice, could you modify the type definitions and make a pr?

chpio commented 7 months ago

I'm still having the same problem, version 4.0.3.