Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 在使用导入进行类型提示时,ESLint diffuse“已定义但从未使用”VS“找不到名称”_Typescript_Vue.js_Eslint_Typescript Eslint - Fatal编程技术网

Typescript 在使用导入进行类型提示时,ESLint diffuse“已定义但从未使用”VS“找不到名称”

Typescript 在使用导入进行类型提示时,ESLint diffuse“已定义但从未使用”VS“找不到名称”,typescript,vue.js,eslint,typescript-eslint,Typescript,Vue.js,Eslint,Typescript Eslint,我刚刚遇到了一个进退两难的局面,我需要你的帮助来知道该怎么办。我正在使用 $ yarn lint -v yarn run v1.22.4 $ eslint . -v v6.8.0 使用插件vue和@typescript eslint,我在一个.ts文件中有这样的内容: import Vue, { VNode } from 'vue'; export default Vue.extend ({ render(createElement): VNode { return create

我刚刚遇到了一个进退两难的局面,我需要你的帮助来知道该怎么办。我正在使用

$ yarn lint -v
yarn run v1.22.4
$ eslint . -v
v6.8.0
使用插件vue和@typescript eslint,我在一个.ts文件中有这样的内容:

import Vue, { VNode } from 'vue';

export default Vue.extend ({
  render(createElement): VNode {
    return createElement('div',
      {},
      'Simple reproducible example'
    );
  }
});
我得到一个错误:

 error  in ./src/components/Demo.ts

Module Error (from ./node_modules/eslint-loader/index.js):

/full/path/to/src/components/Demo.ts
  1:15  error  'VNode' is defined but never used  no-unused-vars
而由WUE cli提供服务的web应用程序也显示了相同的错误,使其无法识别。使用import to typehint似乎并不等同于使用它。因此,我刚刚删除了导入,但出现了以下错误:

ERROR in /full/path/to/src/components/Demo.ts(302,26):
4:26 Cannot find name 'VNode'.
    2 | 
    3 | export default Vue.extend ({
  > 4 |   render(createElement): VNode {
      |                          ^
    5 |     return createElement('div',
    6 |       {},
    7 |       'Simple reproducible example'
这似乎更好,因为至少我可以浏览由Thread serve提供的web应用程序。有没有办法用正确的方法处理这个错误

编辑:.eslintrc.js文件内容
确保将eslint的解析器配置为使用@typescript eslint/parser而不是espree。Typescript的解析方式不同于普通Javascript,并且并非所有适用于Javascript编写的代码的lint规则都适用于Typescript

project提供了一个示例.eslintrc.js文件,您可以从中开始

您可以使用vue插件扩展此配置


确保将eslint的解析器配置为使用@typescript eslint/parser而不是espree。Typescript的解析方式不同于普通Javascript,并且并非所有适用于Javascript编写的代码的lint规则都适用于Typescript

project提供了一个示例.eslintrc.js文件,您可以从中开始

您可以使用vue插件扩展此配置


正如我所说,我已经安装了typescript eslint和vue插件。我将更新我的问题以添加eslintrc文件您是否在项目中使用vue cli?是。我真的很感谢你的帮助,你能试试这个可复制的例子吗?您将在我设置的演示项目中找到eslint的配置。到目前为止,与您的不同之处在于缺少@vue/standard和@vue/typescript。比较演示项目中的tslint.json文件与您的不同也很重要。我将更新我的问题以添加eslintrc文件您是否在项目中使用vue cli?是。我真的很感谢你的帮助,你能试试这个可复制的例子吗?您将在我设置的演示项目中找到eslint的配置。到目前为止,与您的不同之处在于缺少@vue/standard和@vue/typescript。比较演示项目中的tslint.json文件与您的文件之间的差异也很重要
module.exports = {
  'env': {
    'browser': true,
    'es6': true,
    'node': true
  },
  'extends': [
    'eslint:recommended',
    'plugin:vue/essential',
    'plugin:@typescript-eslint/eslint-recommended'
  ],
  'globals': {
    'Atomics': 'readonly',
    'SharedArrayBuffer': 'readonly'
  },
  'parserOptions': {
    'ecmaVersion': 2018,
    'parser': '@typescript-eslint/parser',
    'sourceType': 'module'
  },
  'plugins': [
    'vue',
    '@typescript-eslint'
  ],
  'rules': {
    'indent': [
      'error',
      2
    ],
    'linebreak-style': [
      'error',
      'unix'
    ],
    'quotes': [
      'error',
      'single'
    ],
    'semi': [
      'error',
      'always'
    ]
  }
};
module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  plugins: [
    '@typescript-eslint',
  ],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:vue/recommended',
    '@vue/standard',
    '@vue/typescript'
  ],
};