代码之家  ›  专栏  ›  技术社区  ›  jasmo2

metaInfo失败Gridsome-类型脚本

  •  1
  • jasmo2  · 技术社区  · 5 年前

    我想将Vuejs与typescript和 网格的 .

    typescript端的插件使用是 gridsome插件类型脚本 .

    这是我的 <script>

    <script lang='ts'>
      import Vue from "vue"
    
    export default Vue.extend({
      metaInfo: {
          title: 'About us'
      }
    })
    </script>
    

    我得到以下错误:

    No overload matches this call.
      The last overload gave the following error.
        Argument of type '{ metaInfo: { title: string; }; }' is not assignable to parameter of type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>>'.
          Object literal may only specify known properties, and 'metaInfo' does not exist in type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>>'
    

    它似乎与不接受参数的插件有关。但不确定。

    0 回复  |  直到 5 年前
        1
  •  0
  •   jasmo2    5 年前

    我似乎找到了正确的配置(vue.d.ts):

    旧-坏配置

    declare module "*.vue" {
      import Vue from "vue";
      export default Vue;
    }
    declare module "vue/types/options" {
      interface ComponentOptions<V extends Vue> {
        metaInfo?: any;
      }
    }
    

    我意识到这里有些奇怪,因为在依赖关系中: 节点_模块/vue元/类型/vue。d、 ts 一份声明也在做同样的事情。此外 指数d、 ts 在同一个文件中 导出默认和文本对象 .

    更正代码:

    declare module "*.vue" {
      import * as Vue from "vue";
      export default Vue;
    }
    

    A你现在看到宣言了吗 作为Vue导入* .

    我认为答案是正确的,但如果有反馈,我很乐意阅读。

        2
  •  -1
  •   nabeen    5 年前
    推荐文章