Skip to content

Add JSX.ElementChildrenAttribute change to TypeScript 5.8 release notesΒ #63212

@nmattia

Description

@nmattia

πŸ”Ž Search Terms

tsx, jsx, children, 5.8

πŸ•— Version & Regression Information

  • This changed between versions 5.7.3 and 5.8
  • This changed in commit or PR 60880

⏯ Playground Link

No response

πŸ’» Code

declare global {
  namespace JSX {
    type Element = HTMLElement; /* return type for 'jsx()' */

    /* accepted element tags & attributes */
    type IntrinsicElements = {
      /* All HTML elements */
      [Tag in keyof HTMLElementTagNameMap]: {
        [T in HTMLElementStringAttributes<Tag>]?: string | Dyn<string>;
      } & {
        [T in HTMLElementNumberAttributes<Tag>]?: number | Dyn<number>;
      } & (Tag extends keyof TwrlOverrides ? TwrlOverrides[Tag] : {}) & {
          style?: string /* note: This should probably be CSSStyleDeclaration */;
          // BREAKS HERE without this: children?: Children /* defines the type of children */;
        };
    };
  }
}

πŸ™ Actual behavior

The breaking change is not listed in the 5.8 Release Notes

πŸ™‚ Expected behavior

The breaking change should be listed in the 5.8 Release Notes

Additional information about the issue

I ran into issues when upgrading TypeScript and narrowed it down to 5.7.3 to 5.8. The issues is that children is not inferred by default.

Luckily I came across this discussion: #61354

This led me to this PR: #60880

It would have been much faster if the (breaking) change had been mentioned in the 5.8 release notes. Moreover, one (apparent?) side effect of #61354 is that children does not have a default anymore (i.e. if JSX.ElementChildrenAttribute is not set, pre-5.8 children would be accepted; post-5.8 not anymore).

Here's the JSX implementation that surfaced the issue for me:

declare global {
  namespace JSX {
    type Element = HTMLElement; /* return type for 'jsx()' */

    /* accepted element tags & attributes */
    type IntrinsicElements = {
      /* All HTML elements */
      [Tag in keyof HTMLElementTagNameMap]: {
        [T in HTMLElementStringAttributes<Tag>]?: string | Dyn<string>;
      } & {
        [T in HTMLElementNumberAttributes<Tag>]?: number | Dyn<number>;
      } & (Tag extends keyof TwrlOverrides ? TwrlOverrides[Tag] : {}) & {
          style?: string /* note: This should probably be CSSStyleDeclaration */;
          children?: Children /* defines the type of children */; // <- this is now REQUIRED
        };
    };
  }
}

Fix: nmattia/twrl@d83fde4#diff-8e3158c55134a198f9c40ac714ce358df04312a9ca77d7726e1813fb2ba5b5c0R34

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions