This is effectively a polyfill for Object.assign
, and we should consider emitting the specific helper.
can you elaborate on the request, and why?
We currently emit a call to React.__spread
which has been deprecated for a while now (and might be gone soon?). The official JSX transformer calls _extends
which is initialized with Object.assign || (object.assign polyfill)
__spread
is gone in react 15.0. which means typescript 1.8.9 cannot compile TSX with react 15.0.
My workaround:
import {assign} from 'lodash';
(React as any).__spread = assign;
Workaround without lodash: https://github.com/Microsoft/TypeScript/issues/7270#issuecomment-207138701
@kuon Thank you for the workaround.
I would suggest using object-assign
npm module directly. It is what React uses in 15.
Yeah, but as I had lodash in my project, with typescript definition and all, it was easier.
We鈥檒l temporarily bring it back to avoid breaking everyone using TS: https://github.com/facebook/react/pull/6444. However the method is deprecated and will go away in the next major release.
Thanks so much @gaearon, we really appreciate the temporary rollback.
Proper workaround without lodash:
In a *.d.ts
file, add:
declare module 'object-assign' {
function Assign(target: any, source: any): any;
module Assign { }
export = Assign;
}
In your main *.ts
file, reference your lib file and add:
import * as assign from 'object-assign';
(React as any).__spread = assign;
For clarity, you might want to add object-assign
as an explicit dependency in your package.json
until this is fixed.
A fix is out in #7952. Ideally we can get the change into the next nightly.
Just in case someone else wonders, ES6 Object.assign
works as well:
(React as any).__spread = Object.assign;
(but you need core-js or another polyfill if you're not targeting ES6).
A fix should be out in our nightlies tonight. We'll potentially port the fix to our 1.8 branch.
This should be fixed in TypeScript 1.8.10, which is now on npm and NuGet.
Now that we have this for react, how about getting this for normal TypeScript (primarily because libraries out there e.g. redux
love it) {...foo,{withSomethingMore}}
: https://github.com/Microsoft/TypeScript/issues/2103 :rose:
Most helpful comment
Now that we have this for react, how about getting this for normal TypeScript (primarily because libraries out there e.g.
redux
love it){...foo,{withSomethingMore}}
: https://github.com/Microsoft/TypeScript/issues/2103 :rose: