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

TypeScript imports createElement factory function when using jsx=react-jsx #58574

Closed
dawidgarus opened this issue May 19, 2024 · 2 comments
Closed
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@dawidgarus
Copy link

dawidgarus commented May 19, 2024

πŸ”Ž Search Terms

jsx, createElement, react-jsx

πŸ•— Version & Regression Information

Latest version of TypeScript

⏯ Playground Link

https://www.typescriptlang.org/play/?jsx=4&ts=5.4.5#code/GYVwdgxgLglg9mABAFQKYGcoGlUE8AUADgIYBOxAtugFyIDeiA1nrZqTGAOaIC+AlLWJhc9HgCgxEBJkQlyVHCIC89Ji0QByOZQ28A3BKlh0cADaoAdKbid8AHjSZFa3EoBEwOHDf0Lf7Qp4PIgA9AB8fAZGJuZWNvaO2Hi+-mSU6IrBzK4eXj7hkUA

πŸ’» Code

function TestKey(params: { key: string }): any {}

const paramsKey = { key: 'param' };

console.log(<TestKey key="foo" {...paramsKey} />);
console.log(<TestKey {...paramsKey} key="foo" />);

πŸ™ Actual behavior

Compiled into:

import { createElement as _createElement } from "react";
import { jsx as _jsx } from "react/jsx-runtime";
function TestKey(params) { }
const paramsKey = { key: 'param' };
console.log(_jsx(TestKey, Object.assign({}, paramsKey), "foo"));
console.log(_createElement(TestKey, Object.assign({}, paramsKey, { key: "foo" }))); // what?

πŸ™‚ Expected behavior

Compiled into:

import { jsx as _jsx } from "react/jsx-runtime";
function TestKey(params) { }
const paramsKey = { key: 'param' };
console.log(_jsx(TestKey, Object.assign({}, paramsKey), "foo"));
console.log(_jsx(TestKey, Object.assign({}, paramsKey), "foo"));

Additional information about the issue

No response

@nmain
Copy link

nmain commented May 20, 2024

Babel does the exact same thing. This is expected and explained in detail in facebook/react#20031 (comment). The reasoning is all very React specific, so if you're using react-jsx with something that's not React, you might want to avoid key-after-spread.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 6, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants