mockdeep / typewiz

Automatically discover and add missing types in your TypeScript code
https://medium.com/@urish/manual-typing-is-no-fun-introducing-typewiz-58e3e8813f4c
1.1k stars 46 forks source link

Endless recursion in `getTypeName()` #66

Closed urish closed 6 years ago

urish commented 6 years ago

This happens when an object contains a getter that calls another function, passing the original object as a parameter.

For example, the following code will make TypeWiz throw a RangeError at runtime:

function log(o: { someVal: number }) {
  console.log(o);
}
function f(o: { someVal: number }) {
  return o.someVal;
}
const obj = {
  get someVal() {
    // this will cause TypeWiz to enter an endless recursion when it tries to enumerate to object's keys:
    log(this);
    return 5;
  }
};
f(obj);

Found while working on mweststrate/immer#128