【问题标题】:Invalid typescript environment using vscode使用 vscode 的打字稿环境无效
【发布时间】: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


【解决方案1】:

最终问题是 eslintrc 中的解析器无效。
将解析器从 'babel-eslint' 更改为 @typescript-eslint/parser 并且可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-10
    • 2012-11-24
    • 2016-02-20
    • 2020-11-22
    • 1970-01-01
    • 2017-04-24
    • 2020-11-18
    • 1970-01-01
    相关资源
    最近更新 更多