typescript - Typescript 无法识别属性类型
问题描述
即使我为 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;
解决方案
因此,最终错误在重新启动计算机几次后消失了,就像评论中建议的 Ashish Deora 一样。我的同事建议你也可以在 VS code 中重新启动 Typescript 服务器。当您 ctrl+shift+P 并搜索“typescript”时,会出现此选项。这比重新启动要快得多。
推荐阅读
- ionic-framework - Ionic 3 传单地图位置
- javascript - 当不可见模态时反应本机模态卸载
- c# - 将常规类对象映射到 MVC 模型
- python - 类型提示:给原始数据类型起别名是一种不好的做法吗?
- r - 如何确定在R中连续两个时间段满足特定条件的组
- javascript - Javascript console.log 有效,但输入值未定义
- anaconda - anaconda-navigator 不会使用 UnicodeDecodeError 启动
- windows - 共享计算机上多个用户的批处理脚本
- javascript - javascript中的默认实例函数调用
- java - 如何隐藏方法内部的逻辑但使用proguard保留方法名称