Home > Net >  TypeScript: plugin:prettier/recommended for eslint, unable to use the override keyword
TypeScript: plugin:prettier/recommended for eslint, unable to use the override keyword

Time:10-31

I've got the following eslintrc, which is just the stock config from 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]
  },
};

In my code, I have a class like this:

@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);
  }
}

This code runs fine, but when I try to lint, I get the following error:

/app/src/auth/strategy/firebase.strategy.ts
  22:12  error  Parsing error: Unexpected token  prettier/prettier

Is there a way to fix this? I'd prefer not to have implicit overrides.

CodePudding user response:

It looks like you need to update prettier to any version after 2.3.1 - support was added in that release for TypeScript 4.3 features like the override keyword. You can update this in package.json or use npm i -D prettier@^2.3.1 (assuming you're using npm as your package manager).

  • Related