Control flow analysis for dependant parameters does not work with complex types #51693
Labels
Experience Enhancement
Noncontroversial enhancements
Help Wanted
You can do this
Suggestion
An idea for TypeScript
Milestone
Bug Report
π Search Terms
π Version & Regression Information
TypeScript 4.6.x -> TypeScript 4.9.3 & Nightly
β― Playground Link
Playground link with relevant code
π» Code
The release notes for 4.6 explain how control flow analysis for dependant parameters can work for functions whose arguments are defined as tuples:
However, as soon as you use a more complex type, the code no longer compiles:
π Actual behavior
On the line with
payload.toFixed()
, TypeScript gives the following compiler error:On the line with
payload.toUpperCase()
, TypeScript gives the following compiler error:π Expected behavior
I would expect TypeScript to apply the same control flow analysis for the more complex typed parameters as the simple ones. I'm actually trying to use this feature while playing around with the new decorators that @rbuckton has been working on. I want to make a property decorator work with both accessors and setters, taking advantage of control flow analysis to return the appropriate value without casting.
The text was updated successfully, but these errors were encountered: