gpt4 book ai didi

typescript - ` ' $props ' is declared but its value is never read.` 错误发生在 Vue3/TypeScript 项目中,而 '$props' 没有被显式使用

转载 作者:行者123 更新时间:2023-12-05 03:34:53 36 4
gpt4 key购买 nike

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 (好吧,这不是 repro,但目前除了像 package.json、Webpack 配置和 2 个源文件这样的基本脚手架之外什么都没有。

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

最佳答案

这似乎是 Vue3 模板代码生成的问题。这里有一个 Unresolved 问题: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,
}

关于typescript - ` ' $props ' is declared but its value is never read.` 错误发生在 Vue3/TypeScript 项目中,而 '$props' 没有被显式使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70051535/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com