You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// A *self-contained* demonstration of the problem follows...functionf({ a =false, b ='/'}={}){}f(true);f('lol');f(5);
Expected behavior:
The 3 calls to f should fail at compile time.
Actual behavior:
The calls do not fail.
Comment:
I suppose that typescript consider that the argument to the function is an object. And thus the parameter available inside the function body will simply be this same object but with two extra properties a and b set to their default values.
It makes sense, but it seems completely counter-intuitive to the programmer expectations :)
The text was updated successfully, but these errors were encountered:
The signature of this function is f(arg: { a?: boolean, b?: string }): void;, since this type only has optional members, it is technically assignable from any type (as long as it does not have an a or a b with conflicting properties). This is another manifestation of #7485.
TypeScript Version: 2.3.2
Code
Expected behavior:
The 3 calls to
f
should fail at compile time.Actual behavior:
The calls do not fail.
Comment:
I suppose that typescript consider that the argument to the function is an object. And thus the parameter available inside the function body will simply be this same object but with two extra properties
a
andb
set to their default values.It makes sense, but it seems completely counter-intuitive to the programmer expectations :)
The text was updated successfully, but these errors were encountered: