` '$props' 已声明,但其值从未被读取。` Vue3/TypeScript 项目中发生错误,而 '$props' 尚未明确使用
` '$props' is declared but its value is never read.` error occurred in Vue3/TypeScript project while '$props' has not been explicitly used
Vue3 组件与 TypeScript 和 vue-属性-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(好吧,这不是 repro,但目前除了像 package.json
、Webpack 配置和 2 个源文件这样的基本脚手架之外什么都没有)。
ZIP with included node_modules
只需运行 webpack
得到上面的错误输出。
这似乎是 Vue3 模板代码生成的问题。这里有一个未解决的问题:https://github.com/vuejs/vue-next/issues/4668
最新评论:
Ah, so it is a problem with Vue's codegen in the sense that it generates unused parameters sometimes - which previously wasn't an issue as the generated render function wasn't actually typechecked, but vue-tsc now does that.
so there's little for you to do, we'll have to research if/how we can improve this.
他们建议采用如下 tsconfig.json
中的解决方法:
{
"compilerOptions": {
...
"noUnusedParameters": false,
}
Vue3 组件与 TypeScript 和 vue-属性-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(好吧,这不是 repro,但目前除了像 package.json
、Webpack 配置和 2 个源文件这样的基本脚手架之外什么都没有)。
ZIP with included node_modules
只需运行 webpack
得到上面的错误输出。
这似乎是 Vue3 模板代码生成的问题。这里有一个未解决的问题:https://github.com/vuejs/vue-next/issues/4668
最新评论:
Ah, so it is a problem with Vue's codegen in the sense that it generates unused parameters sometimes - which previously wasn't an issue as the generated render function wasn't actually typechecked, but vue-tsc now does that.
so there's little for you to do, we'll have to research if/how we can improve this.
他们建议采用如下 tsconfig.json
中的解决方法:
{
"compilerOptions": {
...
"noUnusedParameters": false,
}