I want to use gts in my project.
It has the rule in tslint.json "no-any": true
. That rule totally forbids using any
keyword anywhere in the code. What's the common use case of dealing with it function can accept any type. I'm aware that I can override this rule. But I wonder how would someone handle the situation when e.g. function that executes sql accepts arguments of different types. Is there best practices to handle this case?
The only thing that comes in mind is to specify all primitives types via |
param: string| number| Date;
But what if I'm wrapping some external code e.g. mysql in my function that already accepts any[]
.
I think most cases should be covered well by
unknown
.unknown
is a safer alternative toany
. The basic idea is you can assign anything tounknown
just likeany
, but unlikeany
you can't do much withunknown
without explicit checks or type assertions which is probably what you want (see here for details).You might still encounter corner cases where
unknown
can't just replaceany
(type parameters with function constrains understrictFunctionTypes
come to mind), but it should generally work.