Skip to content

TSC Crash: Javascript Object assignment #33006

Closed

Description

@terrance00

TypeScript Version: 3.4.5

Search Terms:
tsc crash for .js where curly bracket object assignment is used in conjunction with OR assignment

Code
tsconfig:

..."allowJs" : true...

simple-js-file.js:

var NameSpace = NameSpace || { Shared: {} }; //DOES NOT WORK

Equivalent works:

var NameSpace = NameSpace || {};
NameSpace.Shared = {}; // WORKS

Expected behavior:
Typescript to compile the .js file to the out folder (Like the second example)

Actual behavior:

tsc : C:\Users\TJevon\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:72970
At line:1 char:1
+ tsc
+ ~~~
    + CategoryInfo          : NotSpecified: (C:\Users\TJevon...ib\tsc.js:72970:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at checkPropertyAccessExpression (C:\Users\TJevon\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:41094:47)
    at checkExpressionWorker (C:\Users\TJevon\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:44380:28)
    at checkExpression (C:\Users\TJevon\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:44317:38)
    at checkTruthinessExpression (C:\Users\TJevon\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:46358:24)
    at checkBinaryLikeExpression (C:\Users\TJevon\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:43762:28)
    at checkBinaryExpression (C:\Users\TJevon\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:43753:20)
    at checkExpressionWorker (C:\Users\TJevon\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:44420:28)
    at checkExpression (C:\Users\TJevon\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:44317:38)
    at checkExpressionCached (C:\Users\TJevon\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:44106:38)
    at getInitializerTypeFromAssignmentDeclaration (C:\Users\TJevon\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:29597:97)

Playground Link:

Related Issues:

Activity

  1. sandersn commented on Oct 15, 2019

    @sandersn
    Member

    terrance00 I tried this program:

    var ns = ns || { shared: {} }

    with this command line:

    tsc --allowjs --noemit test.js
    # and
    tsc --allowjs --outdir out test.js
    
    

    And didn't get a crash on any version of TS 2.2-3.6. Can you share your tsconfig that has the crash?

  2. terrance00 commented on Oct 16, 2019

    @terrance00
    Author

    Nathan Shively-Sanders (@sandersn)

    Sorry, It seems to be when you actually use that anonymous object "shared", and also - you have to go one level deeper:

    Just tested this snippet:

    var ns = ns || { shared: {} };
    
    ns.next = ns.next || {
        shared: {}
    };
    
    ns.next.shared.mymethod = function () {
        return "mystring";
    };
    
  3. sandersn commented on Oct 17, 2019

    @sandersn
    Member

    Thanks, that's it!

  4. sandersn commented on Oct 17, 2019

    @sandersn
    Member

    Crashes from 3.3 onward.

  5. added a commit that references this issue on Oct 17, 2019
    3ce7bd1
  6. added a commit that references this issue on Oct 18, 2019
    82f927f
  7. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions