microsoft / microsoft/TypeScript

Add JSX.ElementChildrenAttribute change to TypeScript 5.8 release notes

Aperta Adatta ai principianti
#63,212 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Docs
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

🔎 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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esaminare la PR 60880 e l’issue 61354 per confermare la modifica del comportamento di JSX.ElementChildrenAttribute, quindi confrontarla con le note di rilascio di TypeScript 5.8. Aggiornare la pagina 5.8 release-notes per descrivere la breaking change e il suo effetto sull’inferenza di children, usando come contesto l’esempio twrl segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
68/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.