I’ve been bitten more than once with floating promises, which refers to promises that are not handled with await, .then, .catch or .finally. For instance:
function checkSomething(): Promise<boolean> { /* ... */ }
if (checkSomething()) {
// do something
}
This codes builds just fine, but will not behave correctly at runtime, given a Promise is always a truthy value. An await is missing in the condition, and this type of errors has happened multiple times in the past.
There are many other examples of errors that could be caught with the proper lints.
So, I’d like to enable the official recommended set of type-checking rules to be added to our ESLint configuration: Shared Configs | typescript-eslint.
I’m using it on multiple personal projects, and I only have seen benefits from it. Note that this wouldn’t enable all type-checking rules, only those who are deemed both important and reliable enough by the typescript-eslint project.
+1 adding a lint check for the example you give initially.
But afaiu recommended-type-checked is much larger than that. Do you know what other kind of additional check it’s going to perform?
It contains quite a number of lints, all of them useful for our codebase IMO. It forbids doing some unsafe operations (like using delete which breaks type safety), running some implicit eval code, prevents propagating any values (forces handling them where they appear), prevents doing additions with non-compatible types (e.g. (a: string, b: never) => a + b is valid by default), prevents duplicate values in enums (e.g. will prevent enum Test { A = 0, B = 0 }), etc.
Ok, thanks for clarifying this. I keep my +1.
Anyway, we’ll quickly see how much this is impacting the existing codebase when introducing the rules in a PR.
And if a specific rule is too restrictive, we can always do another proposal to remove it.