【发布时间】:2019-12-13 08:55:31
【问题描述】:
我正在使用 vscode 编写 React 应用程序(从创建反应应用程序开始),我也在使用 eslint。最近开始整合 Typescript。
出于某种原因,我在编写一些 Typescript 表达式时遇到了问题。例如:
interface Lengthwise {
length: number;
}
function loggingIdentity<T extends Lengthwise>(arg: T): T {
console.log(arg.length); // Now we know it has a .length property, so no more error
return arg;
}
这个例子取自typescriptlang.org page。
我收到以下错误:
知道我的环境出了什么问题吗?
【问题讨论】:
-
我这里采用简单的解决方案:你试过重启 TS lang 服务器和 eslint 吗?
-
是的..没用..也许我做错了?我该怎么做?
-
F1会显示一个操作列表。我想你已经安装了 typescript-eslint?否则 eslint 会尝试将其解析为纯 JS,这显然不是你想要的。 -
我安装了@typescript-eslint/eslint-plugin 和@typescript-eslint/parser。如何重新启动 ts lang 服务器? f1 不显示任何相关操作
-
如果不出意外,重新加载 VS 代码肯定会奏效。
标签: typescript visual-studio-code create-react-app