Description
I'm very sorry if this is not the place for this, but since #24593 is closed I am opening a new, more specific issue.
This is all related to #24423 (--strictAny).
In #24593 @DanielRosenwasser said:
- There are some issues with signatures like (x: any, y: any, ...zs: any[]) => any.
- Now any is subject to contravariant checking.
- Again, can tell users to use never instead of any.
For me this is a major concern since the pattern (...args: any[]) => any
is now the best way to represent a generic function type.
I suppose this can be a generic type-safe function (in the type-safe sense that neither arguments nor return can be used freely without an assertion of some kind):
(...args: never[]) => unknown
Assuming an unknown
type as described here #24439. Again as mentioned, never
seems very counterintuitive in this scenarios, the same for
foo({ /*...*/ } as never)
Semantically, that seems you telling "don't worry, type-checker, that value can never occur". I believe the weird part is the name never
and not the semantics of never
itself.
So I guess my questions are:
With the --strictAny
flag enbled, which is the preferred idiom to any
in a contravariant position? Will be never
a more prominent type and suggested by the TypeScript team? Maybe there are plans to support a different pattern for this (should variadic types help here?)?
Thank you very much in advance.