相关文章推荐
强健的冰淇淋  ·  Machine Learning ...·  7 月前    · 
侠义非凡的炒饭  ·  vue js map object-掘金·  1 年前    · 
重感情的茶壶  ·  swift - How to ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

How to disable @typescript-eslint/explicit-function-return-type for some(), filter(), forEach()?

Ask Question

How to disable @typescript-eslint/explicit-function-return-type for some() , filter() , forEach() ?

It's very annoying to declare a boolean return type for some() and filter() and void for forEach() every time.

Invalid

[2, 5, 8, 1, 4].some(elem => elem > 10)

Valid

[2, 5, 8, 1, 4].some((elem):boolean => elem > 10)

I want to be able to use the first pattern (marked "invalid") without getting errors from this rule.

This is how .eslintrc should be configured for rule @typescript-eslint/explicit-function-return-type

"@typescript-eslint/explicit-function-return-type": "off", "overrides": [ "files": ["*.ts", "*.tsx"], "parser": "@typescript-eslint/parser", "rules": { "@typescript-eslint/explicit-function-return-type": [ "error", "allowExpressions": true

Examples of correct code for this rule with { allowExpressions: true }:

node.addEventListener('click', () => {});
node.addEventListener('click', function() {});
const foo = arr.map(i => i * i);

More info see documentation for allowExpressions.

OMG, after 1 hour of google search and reading documentation I've finally found the solution. Thank you so much! The only thing, "@typescript-eslint/explicit-function-return-type": "off" should be within the rules section. – Kyrylo Zapylaiev Apr 15, 2020 at 10:32
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    "@typescript-eslint/explicit-module-boundary-types": {
      "allowExpressions": true
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.