Objective
I recognize that ESLint is not the ultimate authority and can be customized differently. However, in this query, I am seeking one of the following outcomes:
- Resolve the conflict while adhering to all specified rules
- Be advised to disable the ESLint rule <rule name> because <argumentation> in this specific scenario
Description of Conflict
The code snippet below is valid and functional, but it violates the ESLint rule no-undefined:
@Component
export default class MyComponent extends Vue {
public static getInstanceByReference(
vueReference: Vue | Element | Array<Vue> | Array<Element>
): MyComponent | undefined {
if (vueReference instanceof MyComponent) {
return vueReference;
}
return undefined;
}
}
Removing undefined
from return undefined
would lead to a violation of the no-useless-return rule:
@Component
export default class MyComponent extends Vue {
public static getInstanceByReference(
vueReference: Vue | Element | Array<Vue> | Array<Element>
): MyComponent | undefined {
if (vueReference instanceof MyComponent) {
return vueReference;
}
return;
}
}
If we eliminate the final return
statement which is deemed pointless in terms of JavaScript syntax, it would result in a TypeScript error:
TS7030: Not all code paths return a value.
@Component
export default class MyComponent extends Vue {
public static getInstanceByReference(
vueReference: Vue | Element | Array<Vue> | Array<Element>
): MyComponent | undefined {
if (vueReference instanceof MyComponent) {
return vueReference;
}
}
}
Changing the return value signature to MyComponent | void
would trigger a violation of the no-invalid-void-type rule within @typescript-eslint.