diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b8b215e32f9..3ddf460f80f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21128,7 +21128,7 @@ namespace ts { getUnionType([removeDefinitelyFalsyTypes(leftType), rightType], UnionReduction.Subtype) : leftType; case SyntaxKind.EqualsToken: - const special = getSpecialPropertyAssignmentKind(left.parent as BinaryExpression); + const special = isBinaryExpression(left.parent) ? getSpecialPropertyAssignmentKind(left.parent) : SpecialPropertyAssignmentKind.None; checkSpecialAssignment(special, right); if (isJSSpecialPropertyAssignment(special)) { return leftType; diff --git a/tests/baselines/reference/checkDestructuringShorthandAssigment.errors.txt b/tests/baselines/reference/checkDestructuringShorthandAssigment.errors.txt new file mode 100644 index 00000000000..aca20286905 --- /dev/null +++ b/tests/baselines/reference/checkDestructuringShorthandAssigment.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/bug25434.js(4,9): error TS2304: Cannot find name 'b'. + + +==== tests/cases/compiler/bug25434.js (1 errors) ==== + // should not crash while checking + function Test({ b = '' } = {}) {} + + Test(({ b = '5' } = {})); + ~ +!!! error TS2304: Cannot find name 'b'. + \ No newline at end of file diff --git a/tests/baselines/reference/checkDestructuringShorthandAssigment.symbols b/tests/baselines/reference/checkDestructuringShorthandAssigment.symbols new file mode 100644 index 00000000000..efe0b4f0850 --- /dev/null +++ b/tests/baselines/reference/checkDestructuringShorthandAssigment.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/bug25434.js === +// should not crash while checking +function Test({ b = '' } = {}) {} +>Test : Symbol(Test, Decl(bug25434.js, 0, 0)) +>b : Symbol(b, Decl(bug25434.js, 1, 15)) + +Test(({ b = '5' } = {})); +>Test : Symbol(Test, Decl(bug25434.js, 0, 0)) +>b : Symbol(b, Decl(bug25434.js, 3, 7)) + diff --git a/tests/baselines/reference/checkDestructuringShorthandAssigment.types b/tests/baselines/reference/checkDestructuringShorthandAssigment.types new file mode 100644 index 00000000000..9eccb886051 --- /dev/null +++ b/tests/baselines/reference/checkDestructuringShorthandAssigment.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/bug25434.js === +// should not crash while checking +function Test({ b = '' } = {}) {} +>Test : ({ b }?: { [x: string]: any; }) => void +>b : string +>'' : "" +>{} : { b?: string; } + +Test(({ b = '5' } = {})); +>Test(({ b = '5' } = {})) : void +>Test : ({ b }?: { [x: string]: any; }) => void +>({ b = '5' } = {}) : { b?: any; } +>{ b = '5' } = {} : { b?: any; } +>{ b = '5' } : { [x: string]: any; b?: any; } +>b : any +>{} : { b?: any; } + diff --git a/tests/cases/compiler/checkDestructuringShorthandAssigment.ts b/tests/cases/compiler/checkDestructuringShorthandAssigment.ts new file mode 100644 index 00000000000..e3422aae753 --- /dev/null +++ b/tests/cases/compiler/checkDestructuringShorthandAssigment.ts @@ -0,0 +1,8 @@ +// @allowjs: true +// @checkjs: true +// @noEmit: true +// @Filename: bug25434.js +// should not crash while checking +function Test({ b = '' } = {}) {} + +Test(({ b = '5' } = {}));