Add contextual types infer

This commit is contained in:
kingwl 2020-04-01 16:28:48 +08:00
parent f922427196
commit 9190a2c4e8
2 changed files with 9 additions and 0 deletions

View File

@ -22365,6 +22365,8 @@ namespace ts {
return contextSensitive === true ? getTypeOfExpression(left) : contextSensitive;
case SyntaxKind.BarBarToken:
case SyntaxKind.QuestionQuestionToken:
case SyntaxKind.BarBarEqualsToken:
case SyntaxKind.QuestionQuestionEqualsToken:
// When an || expression has a contextual type, the operands are contextually typed by that type, except
// when that type originates in a binding pattern, the right operand is contextually typed by the type of
// the left operand. When an || expression has no contextual type, the right operand is contextually typed

View File

@ -0,0 +1,7 @@
// @strict: true
// @target: esnext, es2020, es2015
function foo (f: (a: number) => void | undefined) {
f ??= (a => a++)
f ||= (a => a++)
}