【发布时间】:2019-09-12 09:49:46
【问题描述】:
所以,我在 .ts 文件中有这段代码:
import {MicroEventInterface} from '../Interfaces';
export default class MicroEvent implements MicroEventInterface {
// code
而 ESLint 会抛出这个错误:
我在 ESLint 中有这个 TypeScript 配置:
typescript: {
extends: [
'plugin:@private/private/react' // private rep with React config
],
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'import'
],
settings: {
'import/resolver': {
'node': {
'extensions': [
'.js',
'.jsx',
'.ts',
'.tsx'
],
'moduleDirectory': [
'node_modules/',
'src/'
]
}
},
react: {
createClass: 'createClass',
pragma: 'React',
version: '0.14.9'
}
}
}
所以,一切似乎都很好,但我无法克服这个错误。
有什么建议吗?
谢谢!
UPD:
看起来如果我 console.log( --- , MicroEventInterface); 错误消失了。我认为,ESLint 并没有将implements 视为实际使用。
【问题讨论】:
-
ESLint 通常会在导入的模块未在定义范围内使用时抛出此类错误。基本上,它想说的是,“为什么你在不需要的时候还要导入一些东西”。
-
@VikasMishra 是的,我明白这一点。但我实际上将它与“实现”命令一起使用。
-
实现某些东西并不意味着您正在使用它。实施只是规定它符合(可能使用)特定模块(如果需要)。
-
@VikasMishra 那么,我该如何解决这个问题呢?我应该将我的接口与组件放在同一个文件中吗?这是BP吗?
-
@Paleo 在 2019 年使用 TSLint 而不是 ESLint 的有效选项,因为 TSLint 项目已被弃用,有利于将 ESLint 与 TypeScript 一起使用:github.com/palantir/tslint/issues/4534
标签: typescript eslint