microsoft / microsoft/TypeScript

Add JSX.ElementChildrenAttribute change to TypeScript 5.8 release notes

Offen Anfängerfreundlich
#63,212 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Docs
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

🔎 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: https://github.com/microsoft/TypeScript/issues/61354

This led me to this PR: https://github.com/microsoft/TypeScript/pull/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: https://github.com/nmattia/twrl/commit/d83fde44202536c52f2816094fdcc4910c945c85#diff-8e3158c55134a198f9c40ac714ce358df04312a9ca77d7726e1813fb2ba5b5c0R34

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

PR 60880 und Issue 61354 überprüfen, um die Verhaltensänderung von JSX.ElementChildrenAttribute zu bestätigen, und sie anschließend mit den TypeScript 5.8 Release Notes vergleichen. Die 5.8 release-notes-Seite aktualisieren, um die Breaking Change und ihre Auswirkungen auf die Inferenz von children zu beschreiben, wobei das gemeldete twrl-Beispiel als Kontext verwendet wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
documentation
Issue-Typ
Dokumentation
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.