【问题标题】:` '$props' is declared but its value is never read.` error occurred in Vue3/TypeScript project while '$props' has not been explicitly used` '$props' 已声明,但它的值从未被读取。` Vue3/TypeScript 项目中发生错误,而 '$props' 尚未明确使用
【发布时间】:2021-12-31 05:07:16
【问题描述】:

Vue3 组件与 TypeScriptvue-property-decorator

<template lang="pug">

component.OverflowSafeSingleLineLabel(
  :is="rootElementTag"
)
  span.OverflowSafeSingleLineLabel-TextWithIncreasedLineHeight
    slot

</template>


<script lang="ts">

  import { Options, Vue, Prop as VueProperty } from "vue-property-decorator";


  @Options ({})
  export default class OverflowSafeSingleLineLabel extends Vue {

    @Prop({ type: String, default: "div" })
    protected readonly rootElementTag!: string;
  }

</script>

我有 4 个 TypeScript 错误:

ERROR in C:\Users\XXX\Source\OverflowSafeSingleLineLabel.vue.ts
5:45-51
[tsl] ERROR in C:\Users\XXX\Source\OverflowSafeSingleLineLabel.vue.ts(5,46)
      TS6133: '$props' is declared but its value is never read.

ERROR in C:\Users\XXX\Source\OverflowSafeSingleLineLabel.vue.ts
5:57-63
[tsl] ERROR in C:\Users\XXX\Source\OverflowSafeSingleLineLabel.vue.ts(5,58)
      TS6133: '$setup' is declared but its value is never read.

ERROR in C:\Users\XXX\Source\OverflowSafeSingleLineLabel.vue.ts
5:69-74
[tsl] ERROR in C:\Users\XXX\Source\OverflowSafeSingleLineLabel.vue.ts(5,70)
      TS6133: '$data' is declared but its value is never read.

ERROR in C:\Users\XXX\Source\OverflowSafeSingleLineLabel.vue.ts
5:80-88
[tsl] ERROR in C:\Users\XXX\Source\OverflowSafeSingleLineLabel.vue.ts(5,81)
      TS6133: '$options' is declared but its value is never read.

我不明白错误指的是什么。 第 5 行是 template 部分。我在哪里声明了'$props' '$setup''data''$options'

???? Repro repository(嗯,它不是复制品,但目前除了package.json 之类的基本脚手架、Webpack 配置和 2 个源文件之外什么都没有。

???? ZIP with included node_modules 只需运行webpack 即可得到上述错误输出。

【问题讨论】:

    标签: typescript vue.js vuejs3


    【解决方案1】:

    这似乎是 Vue3 模板代码生成的问题。这里有一个未解决的问题:https://github.com/vuejs/vue-next/issues/4668

    最新评论:

    啊,所以 Vue 的 codegen 存在问题,因为它有时会生成未使用的参数 - 这在以前不是问题,因为生成的渲染函数实际上没有经过类型检查,但 vue-tsc 现在可以做到这一点。

    所以您无事可做,我们将不得不研究是否/如何改进这一点。

    他们在tsconfig.json 中建议了一种解决方法:

    {
      "compilerOptions": {
        ...
        "noUnusedParameters": false,
    }
    

    【讨论】:

      猜你喜欢
      • 2019-08-24
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 2023-03-15
      • 1970-01-01
      • 2022-08-10
      • 2018-09-28
      • 1970-01-01
      相关资源
      最近更新 更多