Answer the question
In order to leave comments, you need to log in
Why is it possible to override a function that requires a different signature as input?
The code:
let foo: ({ x: number }) => void
foo = () => null
foo = function () {}
Answer the question
In order to leave comments, you need to log in
firstly, your code is wrong, it should be visible
because type checking is not just comparing function signatures - it is checking that one type can be cast to another.
a function that does not have a parameter can be called in a place where a parameter is passed to it, it will simply ignore it. That is, the type of a function without parameters is converted to a type with parameters.
In fact, if you call it, it will work fine, which the type system takes into account.
try to do the opposite and immediately get an error:
The same if the parameters do not match the types let foo: ( x: number ) => void
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question