TypeScript: Out of memory checking recursive mapped type with two constraint type references

edit: better description of the issue in https://github.com/microsoft/TypeScript/issues/21048#issuecomment-360320359


Hello,

I have the following Node error in one of my project using Typescript:

<--- Last few GCs --->

[6455:0x3fcc3c0]    44547 ms: Mark-sweep 1410.5 (1465.1) -> 1410.4 (1449.1) MB, 1625.7 / 0.0 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking1626 ms) last resort GC in old space requested
[6455:0x3fcc3c0]    46098 ms: Mark-sweep 1410.4 (1449.1) -> 1410.5 (1449.1) MB, 1551.3 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x2198fd4a5ee1 <JSObject>
    2: getTypeListId(aka getTypeListId) [/home/project/node_modules/typescript/lib/typescript.js:~30911] [pc=0x3ee74d14a111](this=0x28fe3da82311 <undefined>,types=0x29df387ac9c9 <JSArray[4]>)
    3: /* anonymous */(aka /* anonymous */) [/home/project/node_modules/typescript/lib/typescript.js:~31668] [pc=0x3ee74d35e07d](this=0x28fe3da82311 <undefined>,t...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x121a2cc [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewRawOneByteString(int, v8::internal::PretenureFlag) [node]
 6: v8::internal::Factory::NewStringFromOneByte(v8::internal::Vector<unsigned char const>, v8::internal::PretenureFlag) [node]
 7: v8::internal::Factory::NumberToString(v8::internal::Handle<v8::internal::Object>, bool) [node]
 8: v8::internal::Runtime_NumberToString(int, v8::internal::Object**, v8::internal::Isolate*) [node]
 9: 0x3ee74d00463d

I’ve spend a lot of time trying to fix it by using various versions of Node, Typescript (including latest dev version), and Webpack. Is there any method I can use to understand this issue?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

So easy. This worked. THANK YOU. Solved everything. 😃

Any import not used as a value will be elided. There’s some info at https://www.typescriptlang.org/docs/handbook/modules.html .

I took another look at the code for .linq. @andy-ms pointed out that if your users import the classes directly and only use them as types, then no import statement gets emitted. However, the classes will still be available for construction at any time, and if the user does happen to construct one, then a real import statement gets emitted. Maybe you could make it hard to construct the classes directly, for example by making constructors private?

Here is a smaller repro that doesn’t depend on ramda and is easier for me to read:

interface A {
  x: PartialDeep<A>;
  calls: number | { };
}
type PartialDeep<T> = { [P in keyof T]?: T[P] & PartialDeep<T[P]> };

declare var deep: PartialDeep<A>;
declare var xdeep: { x: PartialDeep<A> };
deep = xdeep;

Would be helpful to have a bit more context. What, when, where? Do you have any tsconfig.json settings? Can you point to what you are trying to compile/run?