Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React emit should have an '_extends' helper for spread attributes #7270

Closed
DanielRosenwasser opened this issue Feb 26, 2016 · 13 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter Fixed A PR has been merged for this issue

Comments

@DanielRosenwasser
Copy link
Member

This is effectively a polyfill for Object.assign, and we should consider emitting the specific helper.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter labels Feb 26, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Feb 26, 2016

can you elaborate on the request, and why?

@RyanCavanaugh
Copy link
Member

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)

@mhegazy mhegazy added this to the TypeScript 2.0 milestone Feb 26, 2016
@kuon
Copy link

kuon commented Apr 7, 2016

__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: #7270 (comment)

@gaearon
Copy link

gaearon commented Apr 7, 2016

@kuon Thank you for the workaround.
I would suggest using object-assign npm module directly. It is what React uses in 15.

@kuon
Copy link

kuon commented Apr 7, 2016

Yeah, but as I had lodash in my project, with typescript definition and all, it was easier.

@gaearon
Copy link

gaearon commented Apr 7, 2016

We’ll temporarily bring it back to avoid breaking everyone using TS: facebook/react#6444. However the method is deprecated and will go away in the next major release.

@DanielRosenwasser
Copy link
Member Author

Thanks so much @gaearon, we really appreciate the temporary rollback.

@kuon
Copy link

kuon commented Apr 7, 2016

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.

@DanielRosenwasser
Copy link
Member Author

A fix is out in #7952. Ideally we can get the change into the next nightly.

@DanielRosenwasser DanielRosenwasser changed the title React emit should have an '_extends' helper for spread attribute React emit should have an '_extends' helper for spread attributes Apr 8, 2016
@jgillich
Copy link

jgillich commented Apr 8, 2016

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).

@DanielRosenwasser
Copy link
Member Author

A fix should be out in our nightlies tonight. We'll potentially port the fix to our 1.8 branch.

@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label Apr 12, 2016
@DanielRosenwasser
Copy link
Member Author

This should be fixed in TypeScript 1.8.10, which is now on npm and NuGet.

@basarat
Copy link
Contributor

basarat commented Apr 13, 2016

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}}

: #2103 🌹

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

7 participants