fix type checking of variables named "exports" (#52209)
This commit is contained in:
Родитель
cfe1842adf
Коммит
e01ced050c
|
@ -36500,7 +36500,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
|||
if (checkReferenceExpression(left,
|
||||
Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access,
|
||||
Diagnostics.The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access)
|
||||
&& (!isIdentifier(left) || unescapeLeadingUnderscores(left.escapedText) !== "exports")) {
|
||||
) {
|
||||
|
||||
let headMessage: DiagnosticMessage | undefined;
|
||||
if (exactOptionalPropertyTypes && isPropertyAccessExpression(left) && maybeTypeOfKind(valueType, TypeFlags.Undefined)) {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
tests/cases/compiler/typeCheckExportsVariable.ts(2,1): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/typeCheckExportsVariable.ts (1 errors) ====
|
||||
let exports: number;
|
||||
exports = '';
|
||||
~~~~~~~
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
|
@ -0,0 +1,7 @@
|
|||
//// [typeCheckExportsVariable.ts]
|
||||
let exports: number;
|
||||
exports = '';
|
||||
|
||||
//// [typeCheckExportsVariable.js]
|
||||
var exports;
|
||||
exports = '';
|
|
@ -0,0 +1,7 @@
|
|||
=== tests/cases/compiler/typeCheckExportsVariable.ts ===
|
||||
let exports: number;
|
||||
>exports : Symbol(exports, Decl(typeCheckExportsVariable.ts, 0, 3))
|
||||
|
||||
exports = '';
|
||||
>exports : Symbol(exports, Decl(typeCheckExportsVariable.ts, 0, 3))
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
=== tests/cases/compiler/typeCheckExportsVariable.ts ===
|
||||
let exports: number;
|
||||
>exports : number
|
||||
|
||||
exports = '';
|
||||
>exports = '' : ""
|
||||
>exports : number
|
||||
>'' : ""
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
let exports: number;
|
||||
exports = '';
|
Загрузка…
Ссылка в новой задаче