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

Support for Multi-Typed Entities #179

Open
outerlook opened this issue Apr 4, 2022 · 10 comments
Open

Support for Multi-Typed Entities #179

outerlook opened this issue Apr 4, 2022 · 10 comments

Comments

@outerlook
Copy link

Hi! I don't know if I missed something, but it appears not to support Multi-Typed Entities. Is it some typescript limitation?

Thanks in advance!

@NightScript370
Copy link

As someone that uses "WebSite" for the main type but still want access to types from LocalBusiness such as "telephone" and "email", this is MUCH needed for me.

Thank you.

@Eyas
Copy link
Collaborator

Eyas commented Jul 23, 2022

Quick question: How would you expect this to operate, e.g., if you have:

const businessSite: MultiTyped<[WebSite, LocalBusiness]> = {
  // ...
};

would you expect that "@type":

  1. Allows ["WebSite", "LocalBusiness"] and ["LocalBusiness", "WebSite"] ? (that might be hard ish)
  2. Allows only ["WebSite", "LocalBusiness"], or any sub-type of WebSite and any sub-type of LocalBusiness?

@NightScript370
Copy link

Hm, I never actually thought of that. I personally use additionalType, meaning that WebSite would still remain the main, while having any additional type that LocalBusiness has to offer.
Alternatively, maybe I'm just doing schema things wrong and there's a better way to do this. I wish I knew who to contact about this.

@outerlook
Copy link
Author

@Eyas Without getting into too much details, as user, between both I expect the 2nd option. Tuple on generics, same on array and subtypes

@Eyas
Copy link
Collaborator

Eyas commented Aug 25, 2022

Hey @JacobGrady -- In your use cases, would combining the two "leaf" types be acceptable? i.e. the examples give "Restaurant + Brewery" and then uses them as such.

Is there ever a case where you might havea "super-type" in your multi-typed entity?

Eg.

function something(entity: MultiTyped<[FoodEstablishment, EntertainmentBusiness]>) { ...}

something({
  "@type": ["FoodEstablishment", "EntertainmentBusiness"], // works
  ...
})

something({
  "@type": ["Brewery", "ComedyClub"], // also works
  ...
})

The reason I asked is that the second is pretty hard and I haven't figured out a way to support that yet.

@JacobGrady
Copy link

JacobGrady commented Aug 25, 2022

Thanks for the fast reply @Eyas!
We are looking to combine unique properties from multiple types, something like this:

something({
  "@context": "https://schema.org",
  "@type": ["Product", "Book"], 
  "name": "The Catcher in the Rye",
  "author": {
    "@type": "Person",
    "name": "J.D. Salinger"
  },
  "brand": {
    "@type": "Brand",
    "name": "Old School Books"
  },
  "offers": {
    "@type": "AggregateOffer",
      "offerCount": "5",
      "lowPrice": "19.99",
      "highPrice": "99.99",
      "priceCurrency": "USD"
    }
  }
)

In this example it's "author" and "brand", but there are other properties like those. It's entirely possible we are doing this wrong/there is a better way to achieve the same thing. Here's the above passing the rich results test.

image

I did just notice on those Google docs:

Google doesn't show a rich result for Software Apps that only have the [VideoGame] type. To make sure that your Software App is eligible for display as a rich result, co-type the [VideoGame] type with another type. For example:

{
  "@context": "https://schema.org",
  "@type": ["VideoGame", "MobileApplication"],
  ....
}

So at least in that example, Google is requiring a second more specific type?

@Eyas
Copy link
Collaborator

Eyas commented Aug 25, 2022

So at least in that example, Google is requiring a second more specific type?

I'm not sure... I think the SEO folks might have a better answer and reaching out to their support forums directly might be your best bet.

We are looking to combine unique properties from multiple types, something like this:

Yep, I totally agree. But what I'm wondering is what kind of support to sub-types you need.

E.g. if you had a function that expected (Product, Book), are you okay if it only accepted Product and Book types, and not their sub-types?

@JacobGrady
Copy link

E.g. if you had a function that expected (Product, Book), are you okay if it only accepted Product and Book types, and not their sub-types?

100% totally okay with that, I think it's preferred tbh. We would probably want to add the relevant sub-types into that @type array if we had any.

@JacobGrady
Copy link

Not sure if helpful, but here's another example from those Google docs:
https://developers.google.com/search/docs/advanced/structured-data/product#product-properties

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

4 participants