Because functions can be called from other places.
Take this, for example:
let y: (arg: unknown) => any = (arg) => arg
y(123) // fine
This is a perfectly acceptable invocation of y()
. unknown
can be anything, so passing a number there is fine.
Now do this:
let y: (arg: unknown) => any = (arg) => arg
y = (s: string) => s.toUpperCase()
y(123) // crash
number
would no longer be a valid argument for y()
because (s: string) => any
would let the function assume that the argument was a string
, but no guarantee can be made here.
This means that the argument type in the function type unknown
must be assignable to the argument type in what you are assigning string
(because you can still call the function with an unknown
argument). And unknown
is not assignable to string
.