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
Actual behavior: Compilation failure on line this._y = y; with error:
Type 'boolean | undefined' is not assignable to type 'boolean'.
Type 'undefined' is not assignable to type 'boolean'.(2322)
My understanding is that in the else branch of the if, the compiler knows that we are using the first overload, and therefore should be able to infer that y must be defined. Maybe I missed something trivial, but after searching in the documentation and online I did not find any useful hint, so I am reporting the issue.
Ah ok, I definitely encounter a lot that design limitation these days, sorry for the noise then. Nevertheless I am a bit surprised that it is exactly the same problem because the "surface feature of the error" here is quite different than in #38211, in that issue the error was at the call site, while in this issue the error is within the constructor. I would assume that it is easier to analyse types within the constructor, but of course I do not have a full understanding of how type checking works in TS so I might well have a naive reasoning here.
TypeScript Version: 3.8.3 and nightly (tested on Playground as of May 4, 2020)
Search Terms: boolean constructor overload, constructor overload resolution
Code
Expected behavior: I expect this code to compile.
Actual behavior: Compilation failure on line
this._y = y;
with error:My understanding is that in the else branch of the if, the compiler knows that we are using the first overload, and therefore should be able to infer that
y
must be defined. Maybe I missed something trivial, but after searching in the documentation and online I did not find any useful hint, so I am reporting the issue.Related Issues: none found
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: