-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeBugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
We've seen some issues where expressions which are non-obviously parenthesized lose contextual typing and cause issues:
var x: SomeType = (n) => ((m) => q)); // 'm' does not get a contextual parameter type
var y: SomeType = t ? (m => m.length) : undefined; // same here
This trips people up because they don't expect parentheses to change the type system, especially when parens are required to make an expression parse.
With the improvements in the type system with union types, we may have crossed the line where we can more aggressively apply contextual types. The 'new' workaround in cases (if there are any) where a contextual type needs to be avoided would be to use a type assertion to any
or some other type which lacks a contextual impact.
Metadata
Metadata
Assignees
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeBugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue