尽管我为activeNumber()声明了类型,但this.activeIndex +1带有红色下划线,并且VS代码显示“运算符'+‘不能应用于类型’() => any) | ComputedOptions‘和’number‘”。这怎麽可能?我遗漏了什么?
import Vue from 'vue';
interface DataInterface {
questions: [];
results: [];
activeIndex: number;
}
const Component = Vue.extend({
props: {
dataSrc: {
type: String,
default: null
}
},
data(): DataInterface {
return {
questions: [],
results: [],
activeIndex: 0
};
},
computed: {
activeNumber(): number {
return this.activeIndex + 1;
}
})
export default Component;发布于 2021-05-17 17:58:20
因此,就像Ashish Deora在评论中建议的那样,在重新启动我的计算机几次后,这个错误最终消失了。我的同事建议您也可以在VS代码中重新启动Typescript服务器。当你键入并搜索‘ctrl+shift+P’时,这个选项就会出现。这比重启要快得多。
https://stackoverflow.com/questions/67537389
复制相似问题