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 type picked on using WithContext #186

Open
milindsingh opened this issue Sep 14, 2022 · 1 comment
Open

Wrong type picked on using WithContext #186

milindsingh opened this issue Sep 14, 2022 · 1 comment

Comments

@milindsingh
Copy link

I defined a wrapper class to store data, like

export interface MyProduct {
  url: string;
  image?: string;
  name: string;
  sku?: string;
  keywords?: string;
  description?: string;
  schema?: WithContext<Product>;
  meta?: Meta;
}

But when I assign a Product object, it recognizes as Vehicle and throw type error.

const product: MyProduct = {
        "schema": {
            "offers": [
                {
                    "seller": {
                        "name": "XYZ",
                        "@type": "Organization"
                    },
                    "priceCurrency": "INR",
                    "availability": "http://schema.org/InStock",
                    "@type": "Offer",
                    "url": "https://www.xyz.com/en_in/productpage.0874876001.html",
                    "price": "1499.0"
                }
            ],
            "image": "//www.xyz.com/image.jpg",
            "color": "Pigeon blue/Floral",
            "@type": "Product",
            "name": "Fitted cotton sheet",
            "description": "Fitted sheet with an all-over print on fine-threaded, closely-woven cotton with a thread count of 144. Fits mattresses up to 23 cm deep.",
            "sku": "1234567",
            "category": {
                "name": "Sheets",
                "@type": "Thing"
            },
            "@context": "https://schema.org",
            "brand": {
                "name": "XYZ",
                "@type": "Brand"
            },
            "itemCondition": "https://schema.org/NewCondition"
        },
        "image": "//www.xyz.com/image.jpg",
        "meta": {
            "parser": "schema",
            "modifiedDate": "2022-09-14T14:09:18.639Z",
            "createdDate": "2022-09-14T14:09:18.639Z"
        },
        "name": "Fitted cotton sheet",
        "description": "Fitted sheet with an all-over print on fine-threaded, closely-woven cotton with a thread count of 144. Fits mattresses up to 23 cm deep.",
        "sku": "0874876001",
        "url": "https://www.xyz.com/en_in/productpage.0874876001.html"
      }

Error:

Type '"Product"' is not assignable to type '"MotorizedBicycle"'.ts(2322)

Any help or guidance would be appreciated. Thanks

@Eyas
Copy link
Collaborator

Eyas commented Oct 27, 2022

The error is misleading, because type matching is weird, but if you look at the editor you'll see a few errors at a few degrees of nesting:

  • Top Level: 'Your Product Type is wrong' (bad message, it tries to match Product against every product, and fails. Says your product doesn't match a random type. MotorizedBicycle is a type of product. But the real message is that your type doesn't match _any)
    • One Level down, you'll see that the offers array is also complaining. "Your offer is wrong" (It also says offer is not a valid offer for purchase)
      • One level down, you'll notice that availability is wrong. You have http://schema.org/InStock, but we expect https.

Fixing that should fix this error!

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