Skip to content

Keep spread syntax instead of generating Object.assign for ReactJSX and es2018+ #46305

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
webschik opened this issue Oct 11, 2021 · 1 comment · Fixed by #46317
Closed

Keep spread syntax instead of generating Object.assign for ReactJSX and es2018+ #46305

webschik opened this issue Oct 11, 2021 · 1 comment · Fixed by #46317
Labels
Bug A bug in TypeScript
Milestone

Comments

@webschik
Copy link

webschik commented Oct 11, 2021

Bug Report

When I have the next compiler options

"target": "es2019",
"jsx": "react-jsx",

the spread syntax gets always converted to Object.assign call even though it's supported by the ES version.

🔎 Search Terms

🕗 Version & Regression Information

I see that this happens in all versions since 4.1.x (4.5.0-beta as well).

⏯ Playground Link

https://www.typescriptlang.org/play?target=6&jsx=4&ts=4.1.5&ssl=12&ssc=24&pln=1&pc=1#code/JYWwDg9gTgLgBAbwGIFcB2BjGwJoMITi4CmaMAvnAGZSFwDkUxAhlvQNwBQoksczYMABkIAcwgBVKABtqtEAwB0igPTK1q0M1HEAzit0A3USoFgAtNLERFR0R07cyxKFVbE4ABVphdiTnCBcAAWxMCiwTAAXHBoKCAARi5cQXAA7sAAJjDBMXGJyQFBGNLMuroAcswgxAD8MbowUMBoolzkjhi4jXAAgoIi4jGomNi4BERopDAAPN4QvgB8cAC8cAAUYD66AJSryzOgonC6UBgrCGaDkjKUCMqKWwu6lCqLXJzEAB688JnEbhQ0ng-WE1i4QA

💻 Code

import {FunctionComponent} from 'react';
import appLogoUrl from '../../../images/svg/app-logo.svg';

interface Props {
    height: number;
    width: number;
    className?: string;
}

const AppLogo: FunctionComponent<Props> = (props) => <img src={appLogoUrl} {...props} />;

export default AppLogo;

🙁 Actual behavior

import { jsx as _jsx } from "react/jsx-runtime";
import appLogoUrl from '../../../images/svg/app-logo.svg';

const AppLogo = (props) => _jsx("img", Object.assign({ src: appLogoUrl }, props), void 0);

export default AppLogo;

🙂 Expected behavior

import { jsx as _jsx } from "react/jsx-runtime";
import appLogoUrl from '../../../images/svg/app-logo.svg';

const AppLogo = (props) => _jsx("img",  { src: appLogoUrl, ...props }, void 0);

export default AppLogo;
@webschik webschik changed the title Keep spread operator instead of generating Object.assign for ReactJSX and es2018+ Keep spread syntax instead of generating Object.assign for ReactJSX and es2018+ Oct 11, 2021
@MartinJohns
Copy link
Contributor

Related: #42368

Apparently it was fixed already a while ago by @a-tarasyuk in #42554, but I guess the fix only applies to "React" and not to "ReactJSX".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
3 participants