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
The compiler complains about the return this.doSthWithX(localX || false); line. It says:
Argument of type 'PT["x"]' is not assignable to parameter of type 'boolean'.
Type 'boolean | undefined' is not assignable to type 'boolean'.
Type 'undefined' is not assignable to type 'boolean'.
Adding the explicit type for localX solves the problem.
We'd need #22348 or something similar to correctly typecheck this -- it requires the checker understanding that all of the truthy values of the mapped type's x property are boolean, which is not immediately apparent.
TypeScript Version: 3.0.1
Search Terms:
Type inference generics Readonly
Code
Expected behavior:
Code should compile with no errors.
Actual behavior:
The compiler complains about the
return this.doSthWithX(localX || false);
line. It says:Adding the explicit type for
localX
solves the problem.Removing the
Readonly
from the ReactComponent also eliminates the compiler error.Playground Link:
Related Issues:
Perhaps #26418
The text was updated successfully, but these errors were encountered: