TS >=4.1: Cannot assign because it is not a variable (require does not work with let anymore) #41628
Labels
Bug
A bug in TypeScript
checkJs
Relates to checking JavaScript using TypeScript
Design Limitation
Constraints of the existing architecture prevent this from being fixed
Domain: JavaScript
The issue relates to JavaScript specifically
Milestone
Starting with TS 4.1 and also in TS 4.2, it seems that required code is frozen and cannot be reassigned.
We had some code that would require a JSON and conditionally overwrite it, however that code is no longer valid. See example below for a minimal reproduction.
I couldn't find anything in the release notes or breaking changes.
TypeScript Version: 4.1.2
Search Terms:
require json cannot assign let
Code
Expected behavior:
No warnings should be raised for this code. Alternatively at the least I would expect another warning about defining
a
withlet
.Actual behavior:
Playground Link:
https://www.typescriptlang.org/play?ts=4.2.0-dev.20201121&useJavaScript=true#code/DYUwLgBAhhC8ECcQEcCuBLJAKA5AOgHoAHKAYwGsoBzEPAKwGcB7AOxwEoBuAWACgZ4AbzwioAXz5A
Related Issues:
The text was updated successfully, but these errors were encountered: