-
Notifications
You must be signed in to change notification settings - Fork 34
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
WithContext<T> should be assignable to T #158
WithContext<T> should be assignable to T #158
Comments
ItemList
after updating to 0.8ItemList
after updating to 0.8
Thanks for reporting this. I think I'll need to see the exact signature of // typescript 4.5.3
// schema-dts 0.8.3
import { WithContext, ItemList, Article } from 'schema-dts';
const articleList: string[] = [];
function getArticleItemStructuredData({
articleItem: string,
position: number
}): Article {
return {
'@type': 'Article'
};
}
const list: WithContext<ItemList> = {
'@context': 'https://schema.org',
'@type': 'ItemList',
itemListElement: articleList.map((articleItem, i) =>
getArticleItemStructuredData({
articleItem,
position: i + 1
})
)
}; The error, |
Looks like the error comes from the fact that I'm returning Previously this didn't raised any issues, but now it does. Declaring @context at multiple levels is not considered "invalid" by the google validation tools, so we rolled with it for simplicity. But I understand that it's not the intended way to build schemas. Thanks for the help. And thanks for the good work maintaining this library |
Great to hear this was resolved. I see how this would have happened:
and TypeScript now correctly notes that I think including |
ItemList
after updating to 0.8
Fixed in 0.9.0 |
After updating from 0.7 to 0.8, I get errors with this code:
The property
@type
gives the following error:Type '"ItemList"' is not assignable to type '"OfferCatalog"'
I would be able to bypass this error by importing and using
ItemListLeaf
instead ofItemList
, but this interface is not exported. For now my workaround was to recreate the interface (based on the sourcecode, I useOmit<>
to deny all members exceptItemListLeaf
from the intersection).Notice that when I run the output of this code in the Rich Results Test or in the Structured Data Testing Tool, I don't get any errors, that's why I think the problem might not be in my original interface, but in the way the typings are built.
The text was updated successfully, but these errors were encountered: