microsoft / microsoft/TypeScript

Separate JSX/TSX from React and present it as a general XML-in-JS solution

Offen
#62,721 11 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

🔍 Search Terms

"jsx react", "jsx scope", "jsx generic"

✅ Viability Checklist
⭐ Suggestion

Right now TypeScript's JSX/TSX options are tied to React:

  1. This includes jsx tsconfig option names (react, react-jsx, react-native and etc.)
  2. And TypeScript docs (official docs describe JSX/TSX usage only giving examples for React).

All this creates great confusion and makes new people think that JSX/TSX stuff is ONLY used for React which damages the whole idea of jsx. Yes, it used to be like that from historical point of view, but I think it is time to separate one from another.

The problem is that current option names (and tsconfig docs) are not self-explanatory for someone who never worked with React or front end in general.

I think that jsx has grown enought to have it's own independent standart.
Something like this:

"jsx": {
    "mode": "scope" | "import" | "preserve",
    "elementTypeStrictness": "strict" | "relaxed",
    "elementSpec": "two-argument" | "three-argument",
    "elementFactory": "jsx",
    "fragmentFactory": "Fragment",
    "importSource": "...",
}

From that perspective, React will be just one example of how this general feature can be used, not the only one!

Of course it also worth mentioning that there is a awaited by many feature request to provide full generic support for jsx nodes instead of widening to JSX.Element:

📃 Motivating Example

Separating JSX/TSX from React especially on docs level would attract more people to writing their own XML-in-JS languages, instead of using external tools.

💻 Use Cases

This is mainly useful for writing content with strict typings and full JS/TS environment support (variables, conditions, functions, comments and etc) — no need to use external Markdown/XML/... parsers.

Consider the following prose example:

export const pythagoreanTheorem = (
  <Term
      title="Pythagorean Theorem"
      direction="row"
      $snippet={{
          search: { synonyms: ['Pythagoras', 'Right Triangle Theorem'] },
          description:
              'Fundamental theorem relating sides of a right triangle',
      }}
  >
      <TermMain>
          <p>
              In any right triangle, the square of the length of the
              hypotenuse <M>c</M> is equal to the sum of the squares of
              the lengths of the other two sides <M>a</M> and <M>b</M>.
          </p>
          <BlockMath>{`
              a^2 + b^2 = c^2
          `}</BlockMath>
      </TermMain>
      <TermSection title="Geometric Interpretation">
          <p>
              The theorem can be visualized as the area of the square
              constructed on the hypotenuse being equal to the sum of the
              areas of the squares constructed on the other two sides.
              This relationship holds true for all right triangles,
              regardless of their size or orientation.
          </p>
      </TermSection>
      <TermSection title="Common Examples">
          <p>
              The most well-known Pythagorean triple is <M>(3, 4, 5)</M>,
              where <M>3^2 + 4^2 = 9 + 16 = 25 = 5^2</M>. Other common
              triples include <M>(5, 12, 13)</M> and <M>(8, 15, 17)</M>.
          </p>
      </TermSection>
  </Term>
);

This is not a React code. All these tags are custom functions so we can parse it, detect writing errors on both compile and runtime levels, extract search snippets and do so much stuff! And all this within TypeScript — no external tools needed.

Of course XML-in-JS can be used not only for prose content, but for other structured data, that is easier to express with XML structures other than JS code.

Not to mention how flexible it is — we can save such XML structures to variables, export and import them in different files!

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

Beginne mit der Überprüfung der Namen der JSX/TSX-tsconfig-Optionen und der in diesem Issue beschriebenen offiziellen JSX-Dokumentation und vergleiche anschließend, wie sie derzeit an React gekoppelt sind. Als abgeschlossen gilt die Aufgabe, wenn ein abgestimmtes Design für eine unabhängige JSX-Konfiguration und entsprechende Dokumentationsänderungen vorliegt; das Issue nennt keine Implementierungsdateien oder Tests.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, react, typescript
Bereich
compilers, developer-experience, documentation
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

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