typescript - TypeScript:plugin:prettier/recommended for eslint,无法使用 override 关键字
问题描述
软件包版本:
eslint@7.32.0
prettier@2.4.1
eslint-plugin-prettier@4.0.0
我有以下 eslintrc,它只是 NestJS 的库存配置:
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: [
'@typescript-eslint/eslint-plugin',
'filenames'
],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'filenames/match-regex': [2, "^[0-9a-z-.]+$", true]
},
};
这是更漂亮的配置:
{
"singleQuote": true,
"trailingComma": "all"
}
这是 tsconfig:
{
"compilerOptions": {
"moduleResolution": "node",
"module": "commonjs",
"esModuleInterop": true,
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": ".",
"rootDir": ".",
"incremental": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strictNullChecks": true,
"noImplicitAny": true,
"strictBindCallApply": true,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noImplicitOverride": true
}
}
在我的代码中,我有一个这样的类:
@Injectable()
export class FirebaseStrategy extends PassportStrategy(
FirebaseAuthStrategy,
'firebase',
) {
constructor(private usersService: UsersService) {
super({ extractor: ExtractJwt.fromAuthHeaderAsBearerToken() });
}
override async validate(payload: FirebaseUser): Promise<User | undefined> {
return this.usersService.findByFirebaseUid(payload.uid);
}
}
这段代码运行良好,但是当我尝试 lint 时,出现以下错误:
/app/src/auth/strategy/firebase.strategy.ts
22:12 error Parsing error: Unexpected token prettier/prettier
有没有办法来解决这个问题?我不希望有隐式覆盖。
解决方案
看起来您需要将 prettier 更新到 2.3.1 之后的任何版本 - 在该版本中添加了对 TypeScript 4.3 功能(如 override 关键字)的支持。您可以在 package.json 中更新它或使用npm i -D prettier@^2.3.1
(假设您使用 npm 作为包管理器)。
推荐阅读
- python - 使用 kivy、buildozer、matplotlib 和 android 的 mic 绘制实时音频信号
- javascript - JavaScript 余数 (%) 运算符未按预期工作?
- java - 无锁队列:为什么要读两次`Atomic*`?
- c# - Azure 函数 Cronn 表达式在 Azure 计时器触发器中不起作用
- reactjs - react ckeditor5 如何将参数发送到自定义图像上传适配器?
- r - ggpmisc::stat_poly_eq 是否重新计算趋势线数学以获取标签?
- python - ModuleNotFoundError:没有名为“mysql.connector”的模块;
- node.js - fs.createReadStream() 用于 Node 中的 Firebase 远程文件
- botframework - 不提及 MS Teams 机器人就无法接收频道消息
- python - 使用列表推导从 2D 列表创建 2D 列表