` '$props' 已声明,但从未读取其值。` Vue3/TypeScript 项目中发生错误,而 '$props' 尚未显式使用

Gur*_*ofu 3 typescript vue.js vuejs3

带有TypeScriptvue-property-decorator 的Vue3组件:

<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>
Run Code Online (Sandbox Code Playgroud)

我有 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.
Run Code Online (Sandbox Code Playgroud)

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

重现存储库(嗯,这不是重现,但目前除了基本的脚手架package.json,如 Webpack 配置和 2 个源文件之外,什么也没有)。

ZIP 包含node_modules只需运行webpack即可获得上述错误输出。

bla*_*een 6

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

最新评论:

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

所以你没什么可做的,我们必须研究是否/如何改进这一点。

他们建议采用如下所示的解决方法tsconfig.json

{
  "compilerOptions": {
    ...
    "noUnusedParameters": false,
}
Run Code Online (Sandbox Code Playgroud)