ember/no-try-invoke

November 8, 2022 ยท View on GitHub

๐Ÿ’ผ This rule is enabled in the โœ… recommended config.

This rule will catch and prevent the use of tryInvoke.

Rule Details

This rule aims to disallow the usage of tryInvoke. Native JavaScript language now supports optional chaining and developers are encouraged to use optional chaining ?.() instead.

Examples

Examples of incorrect code for this rule:

import { tryInvoke } from '@ember/utils';

class FooComponent extends Component {
  foo() {
    tryInvoke(this.args, 'bar', ['baz']);
  }
}

Examples of correct code for this rule:

class FooComponent extends Component {
  foo() {
    this.args.bar?.('baz');
  }
}

References