useUnknownForAnyReturn and useUnknownForAnyParam #55108
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
⭐ Suggestion
Currently there's
useUnknownInCatchVariables
which allows changing the error type in catch to unknown (from any) by default.Using the same reasoning why that option was introduced, I think it would make sense for 1 or 2 more options in a similar vein:
useUnknownForAnyReturn: if a function returns "any", treat it as if it were "unknown" when the function is called. This is useful especially with 3rd party libs, but also in general, since "unknown" is much stricter than "any" (which is one of the reasons e.g. @typescript-eslint has a "no-unsafe-assignment" rule - which often cannot be fixed, since the "any" comes from a third party package)
useUnknownForAnyParamCallback: if a function/callback does not have any types specified, the default is any. It would make checking better if it would be treated as "unknown" instead of "any", when this flag is set.
🔍 Search Terms
All mentioned in the suggestion above
✅ Viability Checklist
My suggestion meets these guidelines:
📃 Motivating Example
💻 Use Cases
Stricter type checking to avoid bugs popping up when using 3rd party code/any return, where that value is used in functions that have stricter requirements.
If you look at error data (e.g. sentry) you will see that this is actually the most common error reported from users browsers, as the "any" is an escape hatch from the type system, making type validation in typescript useless in some cases - which is the reason why the
useUnknownInCatchVariables
was implemented already.The text was updated successfully, but these errors were encountered: