TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

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

Open dawidgarus opened this issue 9 months ago • 1 comments

🔎 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

dawidgarus avatar May 19 '24 16:05 dawidgarus