Even though I wish it wasn't the case, TypeScript accepts the code below in strict mode. The function's value
argument is defined as either an unknown
or an any
type, meaning it can be anything at this point as it is being passed along.
However, due to unknown matching and the allowance for a reduction in the number of arguments, the test call is still accepted.
interface Mine { x: number }
function handle(
field: number,
onChange: (field:Mine, value: unknown) => void,
) {
}
function testCall() {
handle(123, (value: unknown) => {})
}
Is there a way to prevent functions from accepting fewer arguments than expected? And is there a way to decline implicit conversions to unknown?