TypeScript: Compilation hangs when using Bluebird promise library
Introduction
Passing bluebird promise from top level application to separate node.js module causing typescript compiler to hang until it gets out of memory. Problem is happening with multiple typescript compiler versions.
Using promises within the same npm module do not cause any of this problems.
** Environment ** TypeScript Version: Version 2.4.1 Latest bluebird library:
@types/bluebird: “^3.5.5”,
bluebird: “^3.5.0”,
Code Simplified example:
// index.ts (separate npm module)
import * as Promise from 'bluebird';
export function init(test: Promise<object>){
// Code
}
// App using module
import {init} from 'extmodule';
init(promise);
Expected behavior: Code should compile.
Actual behavior: Compilation process hangs with extensive memory and processor usage.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (7 by maintainers)
I haven’t found a specific problem besides “Bluebird is very big and recursive”, but I made a fix that gets compile time down to 2.9 seconds. This is still considerably slower than the 1 second with `–noStrictGenericChecks".
I extended the type reference caching improvement to decompose array type arguments. In other words, previously the type reference caching would treat the relation of
A<T>the same asA<U>if neitherTnorUwere constrainted. Now it also treatsA<T[]>the same asA<U[]>. This works because Bluebird has lots of methods that returnBluebird<T[]>.This technique, in fact, generalises to any type reference that is a type argument of a type reference. I’m going to try expanding type references recursively when creating a cache key. The cache keys may get too long, but I think it will be instructive either way.
This problem may be related with
Promisebeing available globally as native promise. Naming bluebird promise imported variable asPromisemay just clash with global name. This is causing typescript compiler to end up with infinite loop until entire process gets out of memory.Another option may be related with BlueBird type definition: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/bluebird/index.d.ts#L71-L76
Progress
BlueBirdtypes