Skip to content

Imports removed by compiler when using object spread in jsx #15472

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

Closed
axelhzf opened this issue Apr 29, 2017 · 2 comments
Closed

Imports removed by compiler when using object spread in jsx #15472

axelhzf opened this issue Apr 29, 2017 · 2 comments

Comments

@axelhzf
Copy link

axelhzf commented Apr 29, 2017

TypeScript Version: 2.3.2

Code

Label.js

import React, { Component } from 'react';
export default class Label extends Component {
  render() {
    const { text } = this.props;
    return <div className="label">{text}</div>
  }
}

Button.js

import React, { Component } from 'react';
import Label from 'Label';

export default class Button extends Component {
  render() {
    const { label, ...rest } = this.props;
    return (
      <div {...rest}>
        <Label text={label} />
      </div>
    )
  }

Expected behavior:

The import Label from 'Label'; should be present in the output of the Button.js

Actual behavior:

The import Label from 'Label'; is being omited.

import React, { Component } from 'react';
var Button = (function (_super) {
    __extends(Button, _super);
    function Button() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Button.prototype.render = function () {
        var _a = this.props, label = _a.label, rest = __rest(_a, ["label"]);
        return (React.createElement("div", __assign({}, rest),
            React.createElement(Label, { text: label })));
    };
    return Button;
}(Component));
export default Button;

The problem is related with the object spread {...rest} . If I remove it the code works correctly.

I have created a repository with this code

https://github.com/axelhzf/ts-transpile-jsx-remove-import

@luggage66
Copy link

luggage66 commented Apr 29, 2017

Reported in #15469 Were you as baffled as I? 🙂

@axelhzf
Copy link
Author

axelhzf commented Apr 29, 2017

Thanks, I did not see your issue before. Closing this issue.

@axelhzf axelhzf closed this as completed Apr 29, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants