[no-unnecessary-type-constraint] fixing as suggested can lead to a TS error #3509
Closed
3 tasks done
Labels
accepting prs
Go ahead, send a pull request that resolves this issue
bug
Something isn't working
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Repro
Consider the following example:
It's dummy but it has a problem: calling
maybe(null)
will throw a runtime error (TypeError: Cannot convert undefined or null to object
). Therefore I'd like Typescript to fail here. It does now, all good so far.The rule
no-unnecessary-type-constraint
suggests replacing<T extends any>
with<T>
, because "Constraining the generic type `T` to `any` does nothing and is unnecessary."So I change it to:
Result: TS is silent, the code is not safe against a runtime error.
Versions
@typescript-eslint/eslint-plugin
^4.25.0
@typescript-eslint/parser
^4.25.0
TypeScript
^4.2.4
ESLint
^7.27.0
node
14.16.0
The text was updated successfully, but these errors were encountered: