Skip to content

Compiler hang on this complicated example #24016

Closed

Description

@zen0wu

TypeScript Version: 2.9.0-dev.20180510
NodeJS Version: 9.11.1
OS Version: Mac OS X 10.13.4

Search Terms: hangs

Code
It's a pretty involved and complicated code. Put it up as a gist for better readability.

https://gist.github.com/shivawu/22053a9292ac694bfc87c97ef3c652bf

Note the last line, if it's commented it out, it compiles just fine. That particular line hangs the compiler.

Expected behavior:
It should type check just fine.

Actual behavior:
The compiler hangs. Taking 100% CPU, memory keeps increasing non-stop.

Playground Link: I would skip that since the code would hang the browser tab :)

Related Issues: #7344, #23458 looks similar as well

Activity

  1. ghost added
    BugA bug in TypeScript
    on May 10, 2018
  2. ahejlsberg commented on Oct 10, 2018

    @ahejlsberg
    Member

    With the compiler currently in master we don't hang on the original example (probably because of #26558), but it still takes 7.5s to type check and allocates over 700,000 types.

    The core issue here is the pattern of using indexed access types to write self-referencing conditional types. It is a Turing Complete device (#14833) and along with that comes the halting problem. It is effectively impossible for us to know if evaluation of such types will ever terminate. For this reason I strongly discourage use of the pattern.

  3. added
    Design LimitationConstraints of the existing architecture prevent this from being fixed
    and removed
    BugA bug in TypeScript
    on Oct 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Design LimitationConstraints of the existing architecture prevent this from being fixed

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions