B
B
BonBon Slick2020-05-20 20:19:15
typescript
BonBon Slick, 2020-05-20 20:19:15

JsonLd for vue + typescript?

@Template
@Component<PageMeta>(
    {
        jsonld() {
            return {
                '@context': 'http://schema.org/',
                '@type':    'Organization',
                'url':      'https://test.tv',
                'logo':     'static/favico/android-chrome-192x192.png',
            };
        },


] ERROR in /var/www/test/src/components/public/partials/page_meta/PageMeta.ts(18,9)

      TS2345: Argument of type '{ jsonld(): { '@context': string; '@type': string; url: string; logo: string; }; 
metaInfo(): MetaInfo; }' is not assignable to parameter of type 'ComponentOptions<PageMeta, DefaultData<PageMeta>, 
DefaultMethods<PageMeta>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>> & ThisType<...>'.

  Object literal may only specify known properties, and 'jsonld' does not exist in type 'ComponentOptions<PageMeta, 
DefaultData<PageMeta>, DefaultMethods<PageMeta>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>> 
& ThisType<...>'.

https://github.com/ariesjia/vue-jsonld/issues/12

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-05-20
@BonBonSlick

If there is no typing for something, you first look in @types/<libname>and if there is none, you make it yourself.
This is the reality of typescript - you work primarily in a javascript environment.
Add the following interface extension somewhere:

declare module 'vue/types/options' {
  interface ComponentOptions<V extends Vue> {
    jsonld?: any; // на самом деле не any, а то чего ждёт либа
  }
}

Liba seems to be written in ts, so why the author did not bother with the package typing. But you can get the necessary declarations from its sorts.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question