Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error TS2321: Excessive stack depth comparing types #16997

Closed
damianaiamad opened this issue Jul 7, 2017 · 2 comments
Closed

error TS2321: Excessive stack depth comparing types #16997

damianaiamad opened this issue Jul 7, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@damianaiamad
Copy link

TypeScript Version: 2.4.1 / typescript@2.5.0-dev.20170629

Demo contains two packages:

  1. a library package that exports a function
  2. an app package that imports the function. Both sides refer to Immutable.List() and specify immutable 3.8.1.

Issues

  1. When compiling the app package, typescript is unable to determine that the types are actually identical (details below)
  2. Also seems to give quite a performance hit - I have a project where tsc slowed down dramatically when split into multiple packages to share code.
  3. See end for workaround!

I admit almost complete ignorance, but presumably this is because two copies of immutable are present (see --listFiles output below), even though they are identical. I assume tsc bails out when trying to compare each immutable's declarations - could it fall back to compare the immutable package.json/version in such a case rather than failing outright?

I assume all this comparing is the cause of the slow down when splitting code into multiple packages because tsc does not assume that modules could be identical.

Many thanks - Typescript is awesome!

Code

https://github.com/damianaiamad/immutate

lib:

export function moveListItem<T>(data: Immutable.List<T>, selectedIndex: number, newIndex: number, direction?: OrderWhere): Immutable.List<T> {
...

app:

class Test {
    private orderData: Immutable.List<OrderData>

    updateLocally(selectedIndex: number, newIndex: number, where?: OrderWhere) {
        this.orderData = moveListItem(this.orderData, selectedIndex, newIndex, where)
    }
}

Expected behavior:

tsc compiles without error

Actual behavior:

damian$ tsc --listFiles --diagnostics
error TS2321: Excessive stack depth comparing types 'List<OrderData>' and 'List<OrderData>'.
index.ts(12,39): error TS2345: Argument of type 'List<OrderData>' is not assignable to parameter of type 'List<OrderData>'.
  Types of property 'set' are incompatible.
    Type '(index: number, value: OrderData) => List<OrderData>' is not assignable to type '(index: number, value: OrderData) => List<OrderData>'. Two different types with this name exist, but they are unre
lated.
      Type 'List<OrderData>' is not assignable to type 'List<OrderData>'. Two different types with this name exist, but they are unrelated.
/Users/damian/.nvm/versions/node/v7.10.0/lib/node_modules/typescript/lib/lib.es6.d.ts
/Users/damian/EventSoft/Code/immutate/immutate-lib/node_modules/immutable/dist/immutable-nonambient.d.ts
/Users/damian/EventSoft/Code/immutate/immutate-lib/index.ts
/Users/damian/EventSoft/Code/immutate/immutate-app/node_modules/immutable/dist/immutable-nonambient.d.ts
/Users/damian/EventSoft/Code/immutate/immutate-app/index.ts
Files:             5
Lines:         26203
Nodes:         99337
Identifiers:   35318
Symbols:      129226
Types:         49188
Memory used: 138661K
I/O read:      0.01s
I/O write:     0.00s
Parse time:    0.69s
Bind time:     0.28s
Check time:    2.41s
Emit time:     0.06s
Total time:    3.43s

Workaround

Take advantage of path mapping compiler options to force tsc to see only one copy of immutable.

immutate-app/tscongif.json:

    "baseUrl": ".", 
    "paths": {
      "immutable": ["node_modules/immutable"] 
    }

Result:

damian$ ./node_modules/.bin/tsc --diagnostics --listFiles
/Users/damian/EventSoft/Code/immutate/immutate-app/node_modules/typescript/lib/lib.es6.d.ts
/Users/damian/EventSoft/Code/immutate/immutate-app/node_modules/immutable/dist/immutable-nonambient.d.ts
/Users/damian/EventSoft/Code/immutate/immutate-lib/index.ts
/Users/damian/EventSoft/Code/immutate/immutate-app/index.ts
Files:            4
Lines:        23667
Nodes:        92589
Identifiers:  32362
Symbols:      33455
Types:         9620
Memory used: 75709K
I/O read:     0.00s
I/O write:    0.00s
Parse time:   0.72s
Bind time:    0.40s
Check time:   1.43s
Emit time:    0.04s
Total time:   2.59s
@mhegazy
Copy link
Contributor

mhegazy commented Aug 17, 2017

Seems like a duplicate of #17070

@mhegazy mhegazy added the Duplicate An existing issue was already created label Aug 17, 2017
@damianaiamad
Copy link
Author

This issue is resolved by Typescript 2.5 - thanks guys!

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants