Why does the Closure type not check parameters when using the function.

See below

/** * @param {string} a * @param {string} b */ var f = function(a, b){ // ... } /** * @param {string} a * @param {boolean} c */ var h = function(a, c){ f.apply(this, arguments); // no compile error f.apply(this, [a, c]); // no compile error f.call(this, a, c); // compile error: does not match formal parameter } 

Why does Closure only throw an error when using a call and not apply?
Is there a way I can do a closure type - check the parameters even if I use the application?

+6
source share
1 answer

Because (a) the type checker does not yet have the concept of a tuple type and (b) a method with an array literal is rare. When using .call, which determines which argument is assigned, which parameter slot is trivial.

If the type system extends the type of a tuple, it makes sense to put more effort into checking .apply, because the types and length of the array slot are better known.

+2
source

Source: https://habr.com/ru/post/980957/


All Articles