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

TS 5.8 JSX.ElementChildrenAttribute break #61354

Closed
morlay opened this issue Mar 5, 2025 · 3 comments
Closed

TS 5.8 JSX.ElementChildrenAttribute break #61354

morlay opened this issue Mar 5, 2025 · 3 comments

Comments

@morlay
Copy link

morlay commented Mar 5, 2025

πŸ”Ž Search Terms

5.8, return, type

πŸ•— Version & Regression Information

  • This changed between versions 5.7.3 and 5.8

⏯ Playground Link

No response

πŸ’» Code

I defined custom ElementChildrenAttribute, it work well before TS 5.8

declare global {
  namespace JSX {
    // infer children type
    export interface ElementChildrenAttribute {
      $default: {};
    }
  }
}

Once I upgrade to TS 5.8, JSX like below throw the errors.

const $el = <div>test</div>

πŸ™ Actual behavior

Type { children: Element[]; } is not assignable to type

πŸ™‚ Expected behavior

no errors

Additional information about the issue

full custom JSX declare
https://github.com/innoai-tech/vuekit/blob/main/nodepkg/vue-jsx-runtime/src/jsx-runtime.ts#L104-L153

@uhyo
Copy link
Contributor

uhyo commented Mar 5, 2025

Hi there, I'm the one who broke this 😨 (#60880)

But I believe the new error is correct.

A bit of history:

In the classic JSX transpilation mode (jsx: "react") the name of the prop for JSX children is up to the createElement function. Custom JSX runtime could use non-children names. The role of ElementChildrenAttribute is to tell TypeScript the name of the prop used by createElement for JSX children.

const $el = React.createElement("div", null, "test");

However, under the modern jsx: "react-jsx" setting, the name of the prop for JSX children is always children and is hardcoded to the transpilation result.

const $el = _jsx("div", { children: "test" });

This means that in the new mode you can't change the name of children. Therein ElementChildrenAttribute plays no role.

This is why I changed so that ElementChildrenAttribute is ignored under the jsx: "react-jsx" mode.

I believe you should stop using ElementChildrenAttribute and find another way to acomplish what you want (sorry, I'm not sure why you've been using ElementChildrenAttribute in your custom JSX runtime)

@morlay
Copy link
Author

morlay commented Mar 5, 2025

@uhyo Sure.
I will try to find another way to solve it.

However I think it is undocumented break change.

This feature here so many years πŸ˜‚
https://www.typescriptlang.org/docs/handbook/jsx.html#children-type-checking

@morlay
Copy link
Author

morlay commented Mar 6, 2025

resolved.
just force rename public prop $default which as default slot in vue to children

@morlay morlay closed this as completed Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants