schema-dts icon indicating copy to clipboard operation
schema-dts copied to clipboard

Support for Multi-Typed Entities

Open outerlook opened this issue 2 years ago • 10 comments

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!

outerlook avatar Apr 04 '22 23:04 outerlook

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.

NightScript370 avatar Jul 22 '22 00:07 NightScript370

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?

Eyas avatar Jul 23 '22 16:07 Eyas

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.

NightScript370 avatar Jul 24 '22 03:07 NightScript370

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

outerlook avatar Aug 01 '22 14:08 outerlook

Jumping in to say I'd also love to see support for this.

https://json-ld.org/spec/latest/json-ld/#example-14-specifying-multiple-types-for-a-node

https://developers.google.com/search/docs/advanced/structured-data/software-app#extended-properties-for-app-subtypes

JacobGrady avatar Aug 25 '22 01:08 JacobGrady

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.

Eyas avatar Aug 25 '22 15:08 Eyas

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?

JacobGrady avatar Aug 25 '22 21:08 JacobGrady

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?

Eyas avatar Aug 25 '22 21:08 Eyas

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 avatar Aug 25 '22 21:08 JacobGrady

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

JacobGrady avatar Aug 25 '22 22:08 JacobGrady