BREAKING CHANGE:Object Rests Drop Unspreadable Members from Generic Objects

TL;DR

分割代入&スプレッド構文を使った推論が修正された。

Previous

foo.ts
class Thing {
  prop = 42;
  method() {}
}

function foo(thing: Thing) {
  let { prop, ...rest } = thing;
  rest.someMethod();
}

foo(new Thing());

トランスパイル後のJSでエラーになる。

dist/foo.js
class Thing {
    prop = 42;
    method() {}
}
function foo(thing) {
    let { prop, ...rest } = thing;
    rest.someMethod(); // ❌ ERROR! rest === {}
}

foo(new Thing());

Current

TSでエラーが表示されるようになった。

class Thing {
  prop = 42;
  method() {}
}

function foo(thing: Thing) {
  let { prop, ...rest } = thing; // ❌ ERROR!
  rest.someMethod();
}

foo(new Thing());

Last updated