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
classA{constructor();// Error: overload signature not compatible with implconstructor(a: number|undefined){}}classA{constructor();constructor(a?: number){}// this one works}
Expected behavior:
I expected the first example to work especially since the type of parameter a is identical in either constructor implementation. I think it is helpful when writing overloads to not use optional parameters in the implementation signature and be explicit about the types that might exist in each position.
Actual behavior:
The first results in the noted error.
Commentary:
The following error may a moral equivalent of the error I am objecting to:
functionfoo(a: number|undefined){}foo();// error, even though it's "implicitly" passing undefined
but I think this case is different as on the call side the error is justifiable on the grounds that we think it's likely the caller forgot a parameter (even if undefined is an allowable type, you should be explicit).
The text was updated successfully, but these errors were encountered:
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.4.2
Code
Expected behavior:
I expected the first example to work especially since the type of parameter
a
is identical in either constructor implementation. I think it is helpful when writing overloads to not use optional parameters in the implementation signature and be explicit about the types that might exist in each position.Actual behavior:
The first results in the noted error.
Commentary:
The following error may a moral equivalent of the error I am objecting to:
but I think this case is different as on the call side the error is justifiable on the grounds that we think it's likely the caller forgot a parameter (even if undefined is an allowable type, you should be explicit).
The text was updated successfully, but these errors were encountered: