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

Uncaught TypeError: React.__spread is not a function #7959

Closed
solodii opened this issue Apr 8, 2016 · 2 comments
Closed

Uncaught TypeError: React.__spread is not a function #7959

solodii opened this issue Apr 8, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@solodii
Copy link

solodii commented Apr 8, 2016

TypeScript Version:

1.8.9

React Version:

15.0.0

Code

import * as React from 'react';
import * as ReactDOM from 'react-dom';

let test = {a: 1, b: 2};

ReactDOM.render(
    <div {...test} />,
    document.getElementById('app')
);

Actual behavior:
Browser console error "Uncaught TypeError: React.__spread is not a function".

@BernieSumption
Copy link

Just came across this myself. React/babel have changed the way that spread attributes compile. Instead of relying on a utility function React.__spread, the transpiler now emits its own function that does the same job (i.e. merge all spread attributes into one object).

TypeScript should be updated to do the same, but in the mean time here's a polyfill that restores the old function and permits code compiled by TypeScript 1.8.9 to work:

// universal
(React as any).__spread = function(target: any) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

// if you're compiling to ES6
(React as any).__spread = Object.assign;

It's created by copying the function emitted by the latest babel transpiler so i figure it should work perfectly. Initial testing hasn't shown any issues.

@RyanCavanaugh
Copy link
Member

Duplicate of #7270

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants