Readonly properties type narrowing doesn't flow into inner function scopes #29281
Labels
Domain: Control Flow
The issue relates to control flow analysis
Experience Enhancement
Noncontroversial enhancements
Suggestion
An idea for TypeScript
Milestone
TypeScript Version: 3.3.0-dev.20190105
Search Terms: Readonly, strictNullChecks, optional, inner function
Code
Using
strictNullChecks: true
:Expected behavior:
👍 Compile
Actual behavior:
On the expression
t.foo(5);
the following error:Playground Link: https://www.typescriptlang.org/play/index.html#src=interface%20Thing%20%7B%0D%0A%20%20%20%20foo%3F%3A%20(a%3A%20number)%20%3D%3E%20boolean%3B%0D%0A%7D%0D%0A%0D%0Aconst%20t%3A%20Readonly%3CThing%3E%20%3D%20%7B%0D%0A%20%20%20%20foo%3A%20(a)%20%3D%3E%20true%2C%0D%0A%7D%3B%0D%0A%0D%0Aif%20(t.foo%20!%3D%3D%20undefined)%20%7B%0D%0A%20%20%20%20const%20bar%20%3D%20()%20%3D%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20t.foo(5)%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0A
Related Issues:
The text was updated successfully, but these errors were encountered: