Suggestion
🔍 Search Terms
- Control flow
- Aliased conditions
- Type narrowing
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
TypeScript 4.4 added "Control Flow Analysis of Aliased Conditions and Discriminants" which is a great feature, but unfortunately it seems unable to narrow the types on object properties which limits the benefit.
📃 Motivating Example
Take null checks for instance, the following code results in a compiler warning in the AliasedControlFlow-method. The RegularControlFlow method works fine even though it does the exakt same comparison.
interface ITest {
prop?: string;
}
function AliasedControlFlow(test: ITest) {
const hasProp = test.prop != null;
// Object is possibly 'undefined'.
return hasProp ? test.prop.big() : "";
}
function RegularControlFlow(test: ITest) {
return test.prop != null ? test.prop.big() : "";
}
💻 Use Cases
This would really help when converting code that is currently not using strictNullChecks as null checks may already be aliased in existing code.
Suggestion
🔍 Search Terms
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
TypeScript 4.4 added "Control Flow Analysis of Aliased Conditions and Discriminants" which is a great feature, but unfortunately it seems unable to narrow the types on object properties which limits the benefit.
📃 Motivating Example
Take null checks for instance, the following code results in a compiler warning in the
AliasedControlFlow-method. TheRegularControlFlowmethod works fine even though it does the exakt same comparison.💻 Use Cases
This would really help when converting code that is currently not using
strictNullChecksas null checks may already be aliased in existing code.