Skip to content

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

Closed

Description

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

Activity

  1. mhegazy commented on Feb 26, 2016

    @mhegazy
    Contributor

    can you elaborate on the request, and why?

  2. RyanCavanaugh commented on Feb 26, 2016

    @RyanCavanaugh
    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)

  3. kuon commented on Apr 7, 2016

    @kuon

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

  4. gaearon commented on Apr 7, 2016

    @gaearon

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

  5. kuon commented on Apr 7, 2016

    @kuon

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

  6. gaearon commented on Apr 7, 2016

    @gaearon

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

  7. DanielRosenwasser commented on Apr 7, 2016

    @DanielRosenwasser
    MemberAuthor

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

  8. kuon commented on Apr 7, 2016

    @kuon

    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.

  9. DanielRosenwasser commented on Apr 8, 2016

    @DanielRosenwasser
    MemberAuthor

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

  10. changed the title [-]React emit should have an '_extends' helper for spread attribute[/-] [+]React emit should have an '_extends' helper for spread attributes[/+] on Apr 8, 2016
  11. jgillich commented on Apr 8, 2016

    @jgillich

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

  12. DanielRosenwasser commented on Apr 8, 2016

    @DanielRosenwasser
    MemberAuthor

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

  13. DanielRosenwasser commented on Apr 12, 2016

    @DanielRosenwasser
    MemberAuthor

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

  14. basarat commented on Apr 13, 2016

    @basarat
    Contributor

    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 🌹

  15. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitterFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions