mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix type and simplify code
This commit is contained in:
@@ -20813,7 +20813,6 @@ namespace ts {
|
||||
case SyntaxKind.AmpersandAmpersandEqualsToken:
|
||||
case SyntaxKind.QuestionQuestionEqualsToken:
|
||||
return narrowTypeByTruthiness(narrowType(type, expr.right, assumeTrue), expr.left, assumeTrue);
|
||||
|
||||
case SyntaxKind.EqualsEqualsToken:
|
||||
case SyntaxKind.ExclamationEqualsToken:
|
||||
case SyntaxKind.EqualsEqualsEqualsToken:
|
||||
@@ -22437,6 +22436,9 @@ namespace ts {
|
||||
const { left, operatorToken, right } = binaryExpression;
|
||||
switch (operatorToken.kind) {
|
||||
case SyntaxKind.EqualsToken:
|
||||
case SyntaxKind.AmpersandAmpersandEqualsToken:
|
||||
case SyntaxKind.BarBarEqualsToken:
|
||||
case SyntaxKind.QuestionQuestionEqualsToken:
|
||||
if (node !== right) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -22447,8 +22449,6 @@ 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
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace ts {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.BinaryExpression:
|
||||
const binaryExpression = <BinaryExpression>node;
|
||||
if (isLogicalOrCoalescingAssignmentOperator(binaryExpression.operatorToken.kind)) {
|
||||
return transformLogicalAssignmentOperators(binaryExpression);
|
||||
if (isLogicalOrCoalescingAssignmentExpression(binaryExpression)) {
|
||||
return transformLogicalAssignmentOperator(binaryExpression);
|
||||
}
|
||||
// falls through
|
||||
default:
|
||||
@@ -30,56 +30,52 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function transformLogicalAssignmentOperators(binaryExpression: BinaryExpression): VisitResult<Node> {
|
||||
function transformLogicalAssignmentOperator(binaryExpression: AssignmentExpression<Token<LogicalOrCoalescingAssignmentOperator>>): VisitResult<Node> {
|
||||
const operator = binaryExpression.operatorToken;
|
||||
if (isCompoundAssignment(operator.kind) && isLogicalOrCoalescingAssignmentOperator(operator.kind)) {
|
||||
const nonAssignmentOperator = getNonAssignmentOperatorForCompoundAssignment(operator.kind);
|
||||
let left = skipParentheses(visitNode(binaryExpression.left, visitor, isLeftHandSideExpression));
|
||||
let assignmentTarget = left;
|
||||
const right = skipParentheses(visitNode(binaryExpression.right, visitor, isExpression));
|
||||
if (isPropertyAccessExpression(left) || isElementAccessExpression(left)) {
|
||||
const tempVariable = createTempVariable(hoistVariableDeclaration);
|
||||
if (isPropertyAccessExpression(left)) {
|
||||
assignmentTarget = createPropertyAccess(
|
||||
tempVariable,
|
||||
left.name
|
||||
);
|
||||
left = createPropertyAccess(
|
||||
createAssignment(
|
||||
tempVariable,
|
||||
left.expression
|
||||
),
|
||||
left.name
|
||||
);
|
||||
}
|
||||
else {
|
||||
assignmentTarget = createElementAccess(
|
||||
tempVariable,
|
||||
left.argumentExpression
|
||||
);
|
||||
left = createElementAccess(
|
||||
createAssignment(
|
||||
tempVariable,
|
||||
left.expression
|
||||
),
|
||||
left.argumentExpression
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return createBinary(
|
||||
left,
|
||||
nonAssignmentOperator,
|
||||
createParen(
|
||||
const nonAssignmentOperator = getNonAssignmentOperatorForCompoundAssignment(operator.kind);
|
||||
let left = skipParentheses(visitNode(binaryExpression.left, visitor, isLeftHandSideExpression));
|
||||
let assignmentTarget = left;
|
||||
const right = skipParentheses(visitNode(binaryExpression.right, visitor, isExpression));
|
||||
if (isAccessExpression(left)) {
|
||||
const tempVariable = createTempVariable(hoistVariableDeclaration);
|
||||
if (isPropertyAccessExpression(left)) {
|
||||
assignmentTarget = createPropertyAccess(
|
||||
tempVariable,
|
||||
left.name
|
||||
);
|
||||
left = createPropertyAccess(
|
||||
createAssignment(
|
||||
assignmentTarget,
|
||||
right
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
tempVariable,
|
||||
left.expression
|
||||
),
|
||||
left.name
|
||||
);
|
||||
}
|
||||
else {
|
||||
assignmentTarget = createElementAccess(
|
||||
tempVariable,
|
||||
left.argumentExpression
|
||||
);
|
||||
left = createElementAccess(
|
||||
createAssignment(
|
||||
tempVariable,
|
||||
left.expression
|
||||
),
|
||||
left.argumentExpression
|
||||
);
|
||||
}
|
||||
}
|
||||
Debug.fail("unexpected operator: " + operator.kind);
|
||||
|
||||
return createBinary(
|
||||
left,
|
||||
nonAssignmentOperator,
|
||||
createParen(
|
||||
createAssignment(
|
||||
assignmentTarget,
|
||||
right
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1635,6 +1635,12 @@ namespace ts {
|
||||
| SyntaxKind.CommaToken
|
||||
;
|
||||
|
||||
export type LogicalOrCoalescingAssignmentOperator
|
||||
= SyntaxKind.AmpersandAmpersandEqualsToken
|
||||
| SyntaxKind.BarBarEqualsToken
|
||||
| SyntaxKind.QuestionQuestionEqualsToken
|
||||
;
|
||||
|
||||
export type BinaryOperatorToken = Token<BinaryOperator>;
|
||||
|
||||
export interface BinaryExpression extends Expression, Declaration {
|
||||
|
||||
@@ -4450,12 +4450,16 @@ namespace ts {
|
||||
|| token === SyntaxKind.ExclamationToken;
|
||||
}
|
||||
|
||||
export function isLogicalOrCoalescingAssignmentOperator(token: SyntaxKind): boolean {
|
||||
export function isLogicalOrCoalescingAssignmentOperator(token: SyntaxKind): token is LogicalOrCoalescingAssignmentOperator {
|
||||
return token === SyntaxKind.BarBarEqualsToken
|
||||
|| token === SyntaxKind.AmpersandAmpersandEqualsToken
|
||||
|| token === SyntaxKind.QuestionQuestionEqualsToken;
|
||||
}
|
||||
|
||||
export function isLogicalOrCoalescingAssignmentExpression(expr: BinaryExpression): expr is AssignmentExpression<Token<LogicalOrCoalescingAssignmentOperator>> {
|
||||
return isLogicalOrCoalescingAssignmentOperator(expr.operatorToken.kind);
|
||||
}
|
||||
|
||||
export function isAssignmentOperator(token: SyntaxKind): boolean {
|
||||
return token >= SyntaxKind.FirstAssignment && token <= SyntaxKind.LastAssignment;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ b.baz ||= result.baz
|
||||
c.baz ??= result.baz
|
||||
|
||||
a.foo["baz"] &&= result.foo.baz
|
||||
b.foo["baz"] &&= result.foo.baz
|
||||
c.foo["baz"] &&= result.foo.baz
|
||||
b.foo["baz"] ||= result.foo.baz
|
||||
c.foo["baz"] ??= result.foo.baz
|
||||
|
||||
a.foo.bar().baz &&= result.foo.bar().baz
|
||||
b.foo.bar().baz ||= result.foo.bar().baz
|
||||
@@ -30,14 +30,14 @@ c.foo.bar().baz ??= result.foo.bar().baz
|
||||
|
||||
//// [logicalAssignment2.js]
|
||||
"use strict";
|
||||
var _a, _b;
|
||||
var _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
||||
(_c = a).baz && (_c.baz = result.baz);
|
||||
(_d = b).baz || (_d.baz = result.baz);
|
||||
(_a = (_e = c).baz) !== null && _a !== void 0 ? _a : (_e.baz = result.baz);
|
||||
(_f = a.foo)["baz"] && (_f["baz"] = result.foo.baz);
|
||||
(_g = b.foo)["baz"] && (_g["baz"] = result.foo.baz);
|
||||
(_h = c.foo)["baz"] && (_h["baz"] = result.foo.baz);
|
||||
(_j = a.foo.bar()).baz && (_j.baz = result.foo.bar().baz);
|
||||
(_k = b.foo.bar()).baz || (_k.baz = result.foo.bar().baz);
|
||||
(_b = (_l = c.foo.bar()).baz) !== null && _b !== void 0 ? _b : (_l.baz = result.foo.bar().baz);
|
||||
var _a, _b, _c;
|
||||
var _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
||||
(_d = a).baz && (_d.baz = result.baz);
|
||||
(_e = b).baz || (_e.baz = result.baz);
|
||||
(_a = (_f = c).baz) !== null && _a !== void 0 ? _a : (_f.baz = result.baz);
|
||||
(_g = a.foo)["baz"] && (_g["baz"] = result.foo.baz);
|
||||
(_h = b.foo)["baz"] || (_h["baz"] = result.foo.baz);
|
||||
(_b = (_j = c.foo)["baz"]) !== null && _b !== void 0 ? _b : (_j["baz"] = result.foo.baz);
|
||||
(_k = a.foo.bar()).baz && (_k.baz = result.foo.bar().baz);
|
||||
(_l = b.foo.bar()).baz || (_l.baz = result.foo.bar().baz);
|
||||
(_c = (_m = c.foo.bar()).baz) !== null && _c !== void 0 ? _c : (_m.baz = result.foo.bar().baz);
|
||||
|
||||
@@ -69,7 +69,7 @@ a.foo["baz"] &&= result.foo.baz
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>baz : Symbol(baz, Decl(logicalAssignment2.ts, 4, 9))
|
||||
|
||||
b.foo["baz"] &&= result.foo.baz
|
||||
b.foo["baz"] ||= result.foo.baz
|
||||
>b.foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>b : Symbol(b, Decl(logicalAssignment2.ts, 12, 13))
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
@@ -80,7 +80,7 @@ b.foo["baz"] &&= result.foo.baz
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>baz : Symbol(baz, Decl(logicalAssignment2.ts, 4, 9))
|
||||
|
||||
c.foo["baz"] &&= result.foo.baz
|
||||
c.foo["baz"] ??= result.foo.baz
|
||||
>c.foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>c : Symbol(c, Decl(logicalAssignment2.ts, 13, 13))
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
|
||||
@@ -68,8 +68,8 @@ a.foo["baz"] &&= result.foo.baz
|
||||
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>baz : "" | 0 | 1 | 42 | undefined
|
||||
|
||||
b.foo["baz"] &&= result.foo.baz
|
||||
>b.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
b.foo["baz"] ||= result.foo.baz
|
||||
>b.foo["baz"] ||= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
>b.foo["baz"] : "" | 0 | 1 | 42 | undefined
|
||||
>b.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>b : A
|
||||
@@ -81,8 +81,8 @@ b.foo["baz"] &&= result.foo.baz
|
||||
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>baz : "" | 0 | 1 | 42 | undefined
|
||||
|
||||
c.foo["baz"] &&= result.foo.baz
|
||||
>c.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
c.foo["baz"] ??= result.foo.baz
|
||||
>c.foo["baz"] ??= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
>c.foo["baz"] : "" | 0 | 1 | 42 | undefined
|
||||
>c.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>c : A
|
||||
|
||||
@@ -19,8 +19,8 @@ b.baz ||= result.baz
|
||||
c.baz ??= result.baz
|
||||
|
||||
a.foo["baz"] &&= result.foo.baz
|
||||
b.foo["baz"] &&= result.foo.baz
|
||||
c.foo["baz"] &&= result.foo.baz
|
||||
b.foo["baz"] ||= result.foo.baz
|
||||
c.foo["baz"] ??= result.foo.baz
|
||||
|
||||
a.foo.bar().baz &&= result.foo.bar().baz
|
||||
b.foo.bar().baz ||= result.foo.bar().baz
|
||||
@@ -35,8 +35,8 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
||||
(_b = b).baz || (_b.baz = result.baz);
|
||||
(_c = c).baz ?? (_c.baz = result.baz);
|
||||
(_d = a.foo)["baz"] && (_d["baz"] = result.foo.baz);
|
||||
(_e = b.foo)["baz"] && (_e["baz"] = result.foo.baz);
|
||||
(_f = c.foo)["baz"] && (_f["baz"] = result.foo.baz);
|
||||
(_e = b.foo)["baz"] || (_e["baz"] = result.foo.baz);
|
||||
(_f = c.foo)["baz"] ?? (_f["baz"] = result.foo.baz);
|
||||
(_g = a.foo.bar()).baz && (_g.baz = result.foo.bar().baz);
|
||||
(_h = b.foo.bar()).baz || (_h.baz = result.foo.bar().baz);
|
||||
(_j = c.foo.bar()).baz ?? (_j.baz = result.foo.bar().baz);
|
||||
|
||||
@@ -69,7 +69,7 @@ a.foo["baz"] &&= result.foo.baz
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>baz : Symbol(baz, Decl(logicalAssignment2.ts, 4, 9))
|
||||
|
||||
b.foo["baz"] &&= result.foo.baz
|
||||
b.foo["baz"] ||= result.foo.baz
|
||||
>b.foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>b : Symbol(b, Decl(logicalAssignment2.ts, 12, 13))
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
@@ -80,7 +80,7 @@ b.foo["baz"] &&= result.foo.baz
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>baz : Symbol(baz, Decl(logicalAssignment2.ts, 4, 9))
|
||||
|
||||
c.foo["baz"] &&= result.foo.baz
|
||||
c.foo["baz"] ??= result.foo.baz
|
||||
>c.foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>c : Symbol(c, Decl(logicalAssignment2.ts, 13, 13))
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
|
||||
@@ -68,8 +68,8 @@ a.foo["baz"] &&= result.foo.baz
|
||||
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>baz : "" | 0 | 1 | 42 | undefined
|
||||
|
||||
b.foo["baz"] &&= result.foo.baz
|
||||
>b.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
b.foo["baz"] ||= result.foo.baz
|
||||
>b.foo["baz"] ||= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
>b.foo["baz"] : "" | 0 | 1 | 42 | undefined
|
||||
>b.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>b : A
|
||||
@@ -81,8 +81,8 @@ b.foo["baz"] &&= result.foo.baz
|
||||
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>baz : "" | 0 | 1 | 42 | undefined
|
||||
|
||||
c.foo["baz"] &&= result.foo.baz
|
||||
>c.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
c.foo["baz"] ??= result.foo.baz
|
||||
>c.foo["baz"] ??= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
>c.foo["baz"] : "" | 0 | 1 | 42 | undefined
|
||||
>c.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>c : A
|
||||
|
||||
@@ -19,8 +19,8 @@ b.baz ||= result.baz
|
||||
c.baz ??= result.baz
|
||||
|
||||
a.foo["baz"] &&= result.foo.baz
|
||||
b.foo["baz"] &&= result.foo.baz
|
||||
c.foo["baz"] &&= result.foo.baz
|
||||
b.foo["baz"] ||= result.foo.baz
|
||||
c.foo["baz"] ??= result.foo.baz
|
||||
|
||||
a.foo.bar().baz &&= result.foo.bar().baz
|
||||
b.foo.bar().baz ||= result.foo.bar().baz
|
||||
@@ -34,8 +34,8 @@ a.baz &&= result.baz;
|
||||
b.baz ||= result.baz;
|
||||
c.baz ??= result.baz;
|
||||
a.foo["baz"] &&= result.foo.baz;
|
||||
b.foo["baz"] &&= result.foo.baz;
|
||||
c.foo["baz"] &&= result.foo.baz;
|
||||
b.foo["baz"] ||= result.foo.baz;
|
||||
c.foo["baz"] ??= result.foo.baz;
|
||||
a.foo.bar().baz &&= result.foo.bar().baz;
|
||||
b.foo.bar().baz ||= result.foo.bar().baz;
|
||||
c.foo.bar().baz ??= result.foo.bar().baz;
|
||||
|
||||
@@ -69,7 +69,7 @@ a.foo["baz"] &&= result.foo.baz
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>baz : Symbol(baz, Decl(logicalAssignment2.ts, 4, 9))
|
||||
|
||||
b.foo["baz"] &&= result.foo.baz
|
||||
b.foo["baz"] ||= result.foo.baz
|
||||
>b.foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>b : Symbol(b, Decl(logicalAssignment2.ts, 12, 13))
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
@@ -80,7 +80,7 @@ b.foo["baz"] &&= result.foo.baz
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>baz : Symbol(baz, Decl(logicalAssignment2.ts, 4, 9))
|
||||
|
||||
c.foo["baz"] &&= result.foo.baz
|
||||
c.foo["baz"] ??= result.foo.baz
|
||||
>c.foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
>c : Symbol(c, Decl(logicalAssignment2.ts, 13, 13))
|
||||
>foo : Symbol(A.foo, Decl(logicalAssignment2.ts, 0, 13))
|
||||
|
||||
@@ -68,8 +68,8 @@ a.foo["baz"] &&= result.foo.baz
|
||||
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>baz : "" | 0 | 1 | 42 | undefined
|
||||
|
||||
b.foo["baz"] &&= result.foo.baz
|
||||
>b.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
b.foo["baz"] ||= result.foo.baz
|
||||
>b.foo["baz"] ||= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
>b.foo["baz"] : "" | 0 | 1 | 42 | undefined
|
||||
>b.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>b : A
|
||||
@@ -81,8 +81,8 @@ b.foo["baz"] &&= result.foo.baz
|
||||
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>baz : "" | 0 | 1 | 42 | undefined
|
||||
|
||||
c.foo["baz"] &&= result.foo.baz
|
||||
>c.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
c.foo["baz"] ??= result.foo.baz
|
||||
>c.foo["baz"] ??= result.foo.baz : "" | 0 | 1 | 42 | undefined
|
||||
>c.foo["baz"] : "" | 0 | 1 | 42 | undefined
|
||||
>c.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
|
||||
>c : A
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(12,12): error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(13,5): error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(17,12): error TS2532: Object is possibly 'undefined'.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(22,12): error TS2532: Object is possibly 'undefined'.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(27,27): error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts (6 errors) ====
|
||||
==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts (4 errors) ====
|
||||
function foo1 (f?: (a: number) => void) {
|
||||
f ??= (a => a)
|
||||
f(42)
|
||||
@@ -19,8 +17,6 @@ tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): er
|
||||
|
||||
function foo3 (f?: (a: number) => void) {
|
||||
f &&= (a => a)
|
||||
~
|
||||
!!! error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
f(42)
|
||||
~
|
||||
!!! error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
@@ -42,8 +38,6 @@ tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): er
|
||||
|
||||
function bar3 (f?: (a: number) => void) {
|
||||
f &&= (f.toString(), (a => a))
|
||||
~
|
||||
!!! error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
f(42)
|
||||
~
|
||||
!!! error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
|
||||
@@ -43,12 +43,12 @@ function foo3 (f?: (a: number) => void) {
|
||||
>a : number
|
||||
|
||||
f &&= (a => a)
|
||||
>f &&= (a => a) : ((a: any) => any) | undefined
|
||||
>f &&= (a => a) : ((a: number) => number) | undefined
|
||||
>f : ((a: number) => void) | undefined
|
||||
>(a => a) : (a: any) => any
|
||||
>a => a : (a: any) => any
|
||||
>a : any
|
||||
>a : any
|
||||
>(a => a) : (a: number) => number
|
||||
>a => a : (a: number) => number
|
||||
>a : number
|
||||
>a : number
|
||||
|
||||
f(42)
|
||||
>f(42) : void
|
||||
@@ -112,18 +112,18 @@ function bar3 (f?: (a: number) => void) {
|
||||
>a : number
|
||||
|
||||
f &&= (f.toString(), (a => a))
|
||||
>f &&= (f.toString(), (a => a)) : ((a: any) => any) | undefined
|
||||
>f &&= (f.toString(), (a => a)) : ((a: number) => number) | undefined
|
||||
>f : ((a: number) => void) | undefined
|
||||
>(f.toString(), (a => a)) : (a: any) => any
|
||||
>f.toString(), (a => a) : (a: any) => any
|
||||
>(f.toString(), (a => a)) : (a: number) => number
|
||||
>f.toString(), (a => a) : (a: number) => number
|
||||
>f.toString() : string
|
||||
>f.toString : () => string
|
||||
>f : (a: number) => void
|
||||
>toString : () => string
|
||||
>(a => a) : (a: any) => any
|
||||
>a => a : (a: any) => any
|
||||
>a : any
|
||||
>a : any
|
||||
>(a => a) : (a: number) => number
|
||||
>a => a : (a: number) => number
|
||||
>a : number
|
||||
>a : number
|
||||
|
||||
f(42)
|
||||
>f(42) : void
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(12,12): error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(13,5): error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(17,12): error TS2532: Object is possibly 'undefined'.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(22,12): error TS2532: Object is possibly 'undefined'.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(27,27): error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts (6 errors) ====
|
||||
==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts (4 errors) ====
|
||||
function foo1 (f?: (a: number) => void) {
|
||||
f ??= (a => a)
|
||||
f(42)
|
||||
@@ -19,8 +17,6 @@ tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): er
|
||||
|
||||
function foo3 (f?: (a: number) => void) {
|
||||
f &&= (a => a)
|
||||
~
|
||||
!!! error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
f(42)
|
||||
~
|
||||
!!! error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
@@ -42,8 +38,6 @@ tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): er
|
||||
|
||||
function bar3 (f?: (a: number) => void) {
|
||||
f &&= (f.toString(), (a => a))
|
||||
~
|
||||
!!! error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
f(42)
|
||||
~
|
||||
!!! error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
|
||||
@@ -43,12 +43,12 @@ function foo3 (f?: (a: number) => void) {
|
||||
>a : number
|
||||
|
||||
f &&= (a => a)
|
||||
>f &&= (a => a) : ((a: any) => any) | undefined
|
||||
>f &&= (a => a) : ((a: number) => number) | undefined
|
||||
>f : ((a: number) => void) | undefined
|
||||
>(a => a) : (a: any) => any
|
||||
>a => a : (a: any) => any
|
||||
>a : any
|
||||
>a : any
|
||||
>(a => a) : (a: number) => number
|
||||
>a => a : (a: number) => number
|
||||
>a : number
|
||||
>a : number
|
||||
|
||||
f(42)
|
||||
>f(42) : void
|
||||
@@ -112,18 +112,18 @@ function bar3 (f?: (a: number) => void) {
|
||||
>a : number
|
||||
|
||||
f &&= (f.toString(), (a => a))
|
||||
>f &&= (f.toString(), (a => a)) : ((a: any) => any) | undefined
|
||||
>f &&= (f.toString(), (a => a)) : ((a: number) => number) | undefined
|
||||
>f : ((a: number) => void) | undefined
|
||||
>(f.toString(), (a => a)) : (a: any) => any
|
||||
>f.toString(), (a => a) : (a: any) => any
|
||||
>(f.toString(), (a => a)) : (a: number) => number
|
||||
>f.toString(), (a => a) : (a: number) => number
|
||||
>f.toString() : string
|
||||
>f.toString : () => string
|
||||
>f : (a: number) => void
|
||||
>toString : () => string
|
||||
>(a => a) : (a: any) => any
|
||||
>a => a : (a: any) => any
|
||||
>a : any
|
||||
>a : any
|
||||
>(a => a) : (a: number) => number
|
||||
>a => a : (a: number) => number
|
||||
>a : number
|
||||
>a : number
|
||||
|
||||
f(42)
|
||||
>f(42) : void
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(12,12): error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(13,5): error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(17,12): error TS2532: Object is possibly 'undefined'.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(22,12): error TS2532: Object is possibly 'undefined'.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(27,27): error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts (6 errors) ====
|
||||
==== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts (4 errors) ====
|
||||
function foo1 (f?: (a: number) => void) {
|
||||
f ??= (a => a)
|
||||
f(42)
|
||||
@@ -19,8 +17,6 @@ tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): er
|
||||
|
||||
function foo3 (f?: (a: number) => void) {
|
||||
f &&= (a => a)
|
||||
~
|
||||
!!! error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
f(42)
|
||||
~
|
||||
!!! error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
@@ -42,8 +38,6 @@ tests/cases/conformance/esnext/logicalAssignment/logicalAssignment5.ts(28,5): er
|
||||
|
||||
function bar3 (f?: (a: number) => void) {
|
||||
f &&= (f.toString(), (a => a))
|
||||
~
|
||||
!!! error TS7006: Parameter 'a' implicitly has an 'any' type.
|
||||
f(42)
|
||||
~
|
||||
!!! error TS2722: Cannot invoke an object which is possibly 'undefined'.
|
||||
|
||||
@@ -43,12 +43,12 @@ function foo3 (f?: (a: number) => void) {
|
||||
>a : number
|
||||
|
||||
f &&= (a => a)
|
||||
>f &&= (a => a) : ((a: any) => any) | undefined
|
||||
>f &&= (a => a) : ((a: number) => number) | undefined
|
||||
>f : ((a: number) => void) | undefined
|
||||
>(a => a) : (a: any) => any
|
||||
>a => a : (a: any) => any
|
||||
>a : any
|
||||
>a : any
|
||||
>(a => a) : (a: number) => number
|
||||
>a => a : (a: number) => number
|
||||
>a : number
|
||||
>a : number
|
||||
|
||||
f(42)
|
||||
>f(42) : void
|
||||
@@ -112,18 +112,18 @@ function bar3 (f?: (a: number) => void) {
|
||||
>a : number
|
||||
|
||||
f &&= (f.toString(), (a => a))
|
||||
>f &&= (f.toString(), (a => a)) : ((a: any) => any) | undefined
|
||||
>f &&= (f.toString(), (a => a)) : ((a: number) => number) | undefined
|
||||
>f : ((a: number) => void) | undefined
|
||||
>(f.toString(), (a => a)) : (a: any) => any
|
||||
>f.toString(), (a => a) : (a: any) => any
|
||||
>(f.toString(), (a => a)) : (a: number) => number
|
||||
>f.toString(), (a => a) : (a: number) => number
|
||||
>f.toString() : string
|
||||
>f.toString : () => string
|
||||
>f : (a: number) => void
|
||||
>toString : () => string
|
||||
>(a => a) : (a: any) => any
|
||||
>a => a : (a: any) => any
|
||||
>a : any
|
||||
>a : any
|
||||
>(a => a) : (a: number) => number
|
||||
>a => a : (a: number) => number
|
||||
>a : number
|
||||
>a : number
|
||||
|
||||
f(42)
|
||||
>f(42) : void
|
||||
|
||||
@@ -20,8 +20,8 @@ b.baz ||= result.baz
|
||||
c.baz ??= result.baz
|
||||
|
||||
a.foo["baz"] &&= result.foo.baz
|
||||
b.foo["baz"] &&= result.foo.baz
|
||||
c.foo["baz"] &&= result.foo.baz
|
||||
b.foo["baz"] ||= result.foo.baz
|
||||
c.foo["baz"] ??= result.foo.baz
|
||||
|
||||
a.foo.bar().baz &&= result.foo.bar().baz
|
||||
b.foo.bar().baz ||= result.foo.bar().baz
|
||||
|
||||
Reference in New Issue
Block a user