I am in the process of developing an SEO service using Angular's Meta service (https://angular.io/api/platform-browser/Meta)
Within the service, there is a method for managing social media tags that seems to be encountering issues and producing the following error message:
Argument of type '{ name: string; content: string; property?: undefined; } | { property: string; content: string; name?: undefined; }' is not assignable to parameter of type 'MetaDefinition'. Type '{ name: string; content: string; property?: undefined; }' is not assignable to type 'MetaDefinition'. Type '{ name: string; content: string; property?: undefined; }' is not assignable to type '{ [prop: string]: string; }'. Property 'property' is incompatible with index signature. Type 'undefined' is not assignable to type 'string'
This is the syntax of the method:
socialTags(action:string,pageTagContent:PageTagContent) {
const socialTags =[
{name:"twitter:title", content: pageTagContent.pageTitle},
{name:"twitter:description", content: pageTagContent.description},
{name:"twitter:image", content: pageTagContent.image},
{name:"twitter:card", content: pageTagContent.imageLarge},
{property:'og:title', content: pageTagContent.pageTitle},
{property:'og:image', content: pageTagContent.image}
]
if(action === 'update'){
socialTags.forEach( obj => this.meta.updateTag( obj ) ) //obj throws the error
}else{
//something else
}
}
I followed a tutorial as reference for building this service:
The reason behind this issue remains unclear.