i'm trying to create an seo service based on Angular's Meta service (https://angular.io/api/platform-browser/Meta)
one of the methods in the service is social media tags manager. for some reason it keeps failing with this 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'
here is the method syntax:
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've based the service on this tutorial: https://www.tektutorialshub.com/angular/meta-service-in-angular-add-update-meta-tags-example/
not sure why actually.... thanks for the help!