diff --git a/src/compiler.ts b/src/compiler.ts index 22246dde13..a606d6873b 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3436,9 +3436,13 @@ export class Compiler extends DiagnosticEmitter { ): ExpressionRef { var module = this.module; - // void to any if (fromType.kind == TypeKind.VOID) { - assert(toType.kind != TypeKind.VOID); // convertExpression should not be called with void -> void + if (toType.kind == TypeKind.VOID) { + // void to void: Can happen as a result of a foregoing error. Since we + // have an `expr` here that is already supposed to be void, return it. + return expr; + } + // void to any this.error( DiagnosticCode.Type_0_is_not_assignable_to_type_1, reportNode.range, fromType.toString(), toType.toString() diff --git a/tests/compiler/variable-access-in-initializer.json b/tests/compiler/variable-access-in-initializer.json index 44ccbd7698..824a0f8e52 100644 --- a/tests/compiler/variable-access-in-initializer.json +++ b/tests/compiler/variable-access-in-initializer.json @@ -3,6 +3,7 @@ ], "stderr": [ "TS2448: Variable 'variable-access-in-initializer/a' used before its declaration.", + "TS2448: Variable 'variable-access-in-initializer/c' used before its declaration.", "TS2448: Variable 'variable-access-in-initializer/test~b' used before its declaration.", "EOF" ] diff --git a/tests/compiler/variable-access-in-initializer.ts b/tests/compiler/variable-access-in-initializer.ts index 3d3ce749e4..85cfbe80ed 100644 --- a/tests/compiler/variable-access-in-initializer.ts +++ b/tests/compiler/variable-access-in-initializer.ts @@ -1,4 +1,5 @@ var a = (a = 4, 3); // TS2448 +let c = typeof c; function test(): void { let b = (b = 4, 3); // TS2448